From ab1642936c210977eea25f6b57e208ecae3f26ef Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 29 May 2020 20:09:38 +0530 Subject: removed reading of newline character --- src/model_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/model_generation.py b/src/model_generation.py index dcb0788..eecd716 100644 --- a/src/model_generation.py +++ b/src/model_generation.py @@ -267,9 +267,9 @@ class ModelGeneration: fptr = fopen(ip_filename, "r"); if (fptr) { - char line[20]; - int line_port; - while(fscanf(fptr, "%s %d\\n", line, &line_port) == 2) { + char line_ip[20]; + int line_port; + while(fscanf(fptr, "%s %d", line_ip, &line_port) == 2) { ip_count++; } -- cgit From dfe61a0fb01b725478720bfd71aa2a456a3b36dd Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 29 May 2020 21:03:41 +0530 Subject: removed pid comments and related library, added credits --- src/ghdlserver/ghdlserver.c | 54 +++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c index d324e7b..1b1e706 100644 --- a/src/ghdlserver/ghdlserver.c +++ b/src/ghdlserver/ghdlserver.c @@ -1,38 +1,21 @@ -/********************************************************************************** - * FOSSEE, IIT-Bombay - ********************************************************************************** +/************************************************************************************ + * eSim Team, FOSSEE, IIT-Bombay + ************************************************************************************ + * 28.May.2020 - Bladen Martin - Termination of testbench: Replaced Process ID + * mechanism with socket connection from client + * receiving the special close message + ************************************************************************************ + ************************************************************************************ * 08.Nov.2019 - Rahul Paknikar - Switched to blocking sockets from non-blocking - * - Close previous used socket to prevent from - * generating too many socket descriptors - * - Enabled SO_REUSEPORT, SO_DONTROUTE socket options - * 26.Sept.2019 - Rahul Paknikar - Added reading of IP from a file to - * support multiple digital models - * - On exit, the test bench removes the - * NGHDL_COMMON_IP_ file, shared by all - * nghdl digital models and is stored in /tmp - * directory. It tracks the used IPs for existing - * digital models in current simulation. - * - Writes PID file in append mode. + * - Close previous used socket to prevent from + * generating too many socket descriptors + * - Enabled SO_REUSEPORT, SO_DONTROUTE socket options * 5.July.2019 - Rahul Paknikar - Added loop to send all port values for * a given event. - * - Removed bug to terminate multiple testbench - * instances in ngpsice windows. - ********************************************************************************** - ********************************************************************************** - * 24.Mar.2017 - Raj Mohan - Added signal handler for SIGUSR1, to handle an - * orphan test bench process. - * The test bench will now create a PID file in - * /tmp directory with the name - * NGHDL___ - * This file contains the PID of the test bench . - * On exit, the test bench removes this file. - * The SIGUSR1 signal serves the same purpose as the - * "End" signal. - * - Added syslog interface for logging. + ************************************************************************************ + ************************************************************************************ + * 24.Mar.2017 - Raj Mohan - Added syslog interface for logging. * - Enabled SO_REUSEADDR socket option. - * - Added the following functions: - * o create_pid_file() - * o get_ngspice_pid() * 22.Feb.2017 - Raj Mohan - Implemented a kludge to fix a problem in the * test bench VHDL code. * - Changed sleep() to nanosleep(). @@ -40,7 +23,7 @@ * Added the following functions: * o curtim() * o print_hash_table() - *********************************************************************************/ + ***********************************************************************************/ #include #include "ghdlserver.h" @@ -60,7 +43,6 @@ #include #include #include -#include #include #define _XOPEN_SOURCE 500 @@ -240,13 +222,13 @@ static void receive_string(int sock_id, char* buffer) nbytes = recv(sock_id, buffer, MAX_BUF_SIZE, 0); if (nbytes <= 0) { - perror("receive_string() - READ FAILURE "); + perror("receive_string() - READ FAILURE "); exit(1); } - //28.May.2020 - BM - Added method to close server by NGSPICE after simulation + // 28.May.2020 - BM - Added method to close server by Ngspice after simulation char *exitstr = "CLOSE_FROM_NGSPICE"; - if (strcmp(buffer, exitstr)==0) + if (strcmp(buffer, exitstr) == 0) { Vhpi_Exit(0); } -- cgit From cb798c842a17fa58520e6f0184b165728b41c5d4 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 29 May 2020 21:05:34 +0530 Subject: multiple retries for closing the server --- src/outitf.c | 140 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/src/outitf.c b/src/outitf.c index c015c04..9f1a851 100644 --- a/src/outitf.c +++ b/src/outitf.c @@ -3,17 +3,6 @@ Copyright 1990 Regents of the University of California. All rights reserved. Author: 1988 Wayne A. Christopher, U. C. Berkeley CAD Group Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski **********/ -/************************************************************************** - * 10.Mar.2017 - RM - Added a dirty fix to handle orphan FOSSEE test bench - * processes. The following static functions were added in the process: - * o nghdl_orphan_tb() - * o nghdl_tb_SIGUSR1() - **************************************************************************/ -/************************************************************************** - * 22.Oct.2019 - RP - Read all the PIDs and send kill signal to all those - * processes. Also, Remove the common file of used IPs and PIDs for this - * Ngspice's instance rather than depending on GHDLServer to do the same. - **************************************************************************/ /* * This module replaces the old "writedata" routines in nutmeg. * Unlike the writedata routines, the OUT routines are only called by @@ -21,6 +10,12 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski * of nutmeg doesn't deal with OUT at all. */ +/************************************************************************** + * 29.May.2020 - RP, BM - Read all the IPs and ports from NGHDL_COMMON_IP + * file from /tmp folder. It connects to each of the ghdlserver and sends + * CLOSE_FROM_NGSPICE message to terminate themselves + **************************************************************************/ + #include "ngspice/ngspice.h" #include "ngspice/cpdefs.h" #include "ngspice/ftedefs.h" @@ -34,7 +29,6 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski #include "circuits.h" #include "outitf.h" #include "variable.h" -#include #include "ngspice/cktdefs.h" #include "ngspice/inpdefs.h" #include "breakp2.h" @@ -43,18 +37,19 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski #include "../misc/misc_time.h" /* 10.Mar.2917 - RM - Added the following #include */ -#include +#include #include #include #include #include #include -// 27.May.2020 - BM - Added the following #include + +/* 27.May.2020 - BM - Added the following #include */ #include #include #include #include -#include + extern char *spice_analysis_get_name(int index); extern char *spice_analysis_get_description(int index); @@ -102,7 +97,7 @@ int fixme_onoise_type = SV_NOTYPE; int fixme_inoise_type = SV_NOTYPE; -#define DOUBLE_PRECISION 15 +#define DOUBLE_PRECISION 15 static clock_t lastclock, currclock; @@ -119,40 +114,75 @@ static bool savenone = FALSE; #endif -//28.May.2020 - BM - Closing the GHDL server after simulation is over - -static void close_server(void) +/* 28.May.2020 - RP, BM - Closing the GHDL server after simulation is over */ +static void close_server() { FILE *fptr; char ip_filename[48]; sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt", getpid()); - fptr = fopen(ip_filename, "r"); - if (fptr) - { - char IPaddr_file[20]; - int PORT_file; - while(fscanf(fptr, "%s %d\n", IPaddr_file, &PORT_file) == 2) - { printf("\nIPaddr - %s portno - %d", IPaddr_file, PORT_file); - int sock = 0; - struct sockaddr_in serv_addr; - char *message = "CLOSE_FROM_NGSPICE"; - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - printf("\n Socket creation error \n"); - } - - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(PORT_file); - serv_addr.sin_addr.s_addr = inet_addr(IPaddr_file); + fptr = fopen(ip_filename, "r"); + + if(fptr) + { + char server_ip[20], *message = "CLOSE_FROM_NGSPICE"; + int port = -1, sock = -1, try_limit = 0, skip_flag = 0; + struct sockaddr_in serv_addr; + serv_addr.sin_family = AF_INET; + + /* scan server ip and port to send close message */ + while(fscanf(fptr, "%s %d\n", server_ip, &port) == 2) + { + /* Create socket descriptor */ + try_limit = 10, skip_flag = 0; + while(try_limit > 0) + { + if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + sleep(0.2); + try_limit--; + if(try_limit == 0) + { + perror("\nClient Termination - Socket Failed: "); + skip_flag = 1; + } + } + else + break; + } + + if (skip_flag) + continue; - if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - printf("\nConnection Failed\n"); - } - send(sock , message , strlen(message) , 0 ); - close(sock); - } - } + serv_addr.sin_port = htons(port); + serv_addr.sin_addr.s_addr = inet_addr(server_ip); + + /* connect with the server */ + try_limit = 10, skip_flag = 0; + while(try_limit > 0) + { + if(connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + sleep(0.2); + try_limit--; + if(try_limit == 0) + { + perror("\nClient Termination - Connection Failed: "); + skip_flag = 1; + } + } + else + break; + } + + if (skip_flag) + continue; + + /* send close message to the server */ + send(sock, message, strlen(message), 0); + close(sock); + } + } + remove(ip_filename); } @@ -1083,15 +1113,13 @@ fileEndPoint(FILE *fp, bool bin) static void fileEnd(runDesc *run) { - /* 10.Mar.2017 - RM - Check if any orphan test benches are running. If any are + /* 28.May.2020 - RP, BM - Check if any orphan test benches are running. If any are * found, force them to exit. */ - //nghdl_orphan_tb(); - /* End 10.Mar.2017 */ - /* 28.MaY.2020 - BM */ - close_server; - /* End 28.MaY.2020 */ + /* 28.May.2020 - BM */ + close_server(); + /* End 28.May.2020 */ if (run->fp != stdout) { @@ -1246,13 +1274,9 @@ plotAddComplexValue(dataDesc *desc, IFcomplex value) static void plotEnd(runDesc *run) { - /* 10.Mar.2017 - RM */ - //nghdl_orphan_tb(); - /* End 10.Mar.2017 */ - - /* 28.MaY.2020 - BM */ - close_server; - /* End 28.MaY.2020 */ + /* 28.May.2020 - BM, RP */ + close_server(); + /* End 28.May.2020 */ fprintf(stdout, "\nNo. of Data Rows : %d\n", run->pointCount); -- cgit