📄 eibdrv_sim.c
字号:
/* --------------------------------------------------------------------------- eibdrv_sim.c --------------------------------------------------------------------------- eibdrv_sim Version 0.2.1 Copyright (C) 2002, Wolfgang Tumfart Donaustrasse 104/9 A-2344 Maria Enzersdorf Austria (Europe) tumfart@auto.tuwien.ac.at This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --------------------------------------------------------------------------- *//* --------------------------------------------------------------------------- This program serves as a benchmark program for the eibdrv driver environment to evaluate actual throughput and reliablity of the eibdrv driver operating the FT1.2 protocol by simulating the driver load of multiple writing and reading user programs. * A certain number of write processes are forked, that write at random points in time within time intervals of certain length messages of random length within certain length limits to the eibdrv driver. * An equal number of read processes are forked, that collect messages from the eibdrv driver as soon as they are available. All processes are stopped and exited after a vertain run time and the various data about throughput of the driver and the simulation system and the theoretical upper limit are displayed in a panel and are written to a log file. All simulation parameter are chosen by the operator in the main window of the program. --------------------------------------------------------------------------- *//* --------------------------------------------------------------------------- FormsLibrary is copyrighted by T.C. Zhao and Mark Overmars. It is not public domain, but may be used for running publically available free software. --------------------------------------------------------------------------- */#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <time.h>#include <termios.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/wait.h>#include <sys/sem.h>#include <sys/ipc.h>#include <sys/shm.h>#include <sys/time.h>#include <sys/times.h>#include "forms.h"#include "eibdrv.h"#include "eibdrv_fl.h"#define EIBDRV_SIM_LOGFILE "eibdrv_sim.log" // File for result log#define EIBDRV_SIM_PANELFILE "/sbin/eibdrv_sim.panel" // File with panel messages#define EIBDRV_SIM_PANELFILESIZE 12 // Number of panels in panelfile#define EIBDRV_SIM_NONBLOCKSTDWMODE 1 // Nonblocking standard write mode#define EIBDRV_SIM_BLOCKSTDWMODE 2 // Blocking standard write mode#define EIBDRV_SIM_NONBLOCKACKWMODE 3 // Nonblocking acknowledged write mode#define EIBDRV_SIM_BLOCKACKWMODE 4 // Blocking acknowledged write mode#define EIBDRV_SIM_INTERVAL 1 // Fixed length time intervals#define EIBDRV_SIM_REDINTERVAL 2 // Variable length time intervals#define EIBDRV_SIM_W1_COL FL_PALEGREEN // Bar for 1-Writes and 0-Reads#define EIBDRV_SIM_W2_COL FL_DARKCYAN // Bar for 2-Writes and 1-Reads#define EIBDRV_SIM_W3_COL FL_ORCHID // Bar for 3-Writes and 2-Reads#define EIBDRV_SIM_WFAILED_COL FL_TOMATO // Bar for failed-Writes#define EIBDRV_SIM_STATE_INIT 1#define EIBDRV_SIM_STATE_READY 2#define EIBDRV_SIM_STATE_RUNNING 3#define EIBDRV_SIM_STATE_SHUTDOWN 4/* Main Form */typedef struct { FL_FORM *VisForm; void *vdata; char *cdata; long ldata; FL_OBJECT *DeviceText; FL_OBJECT *ModeText; FL_OBJECT *RunTimeCounter; FL_OBJECT *IntervalCounter; FL_OBJECT *MaxLengthCounter; FL_OBJECT *MinLengthCounter; FL_OBJECT *ProcessCounter; FL_OBJECT *NonblockingWModeCheckbtn; FL_OBJECT *BlockingWModeCheckbtn; FL_OBJECT *NonblockingAckWModeCheckbtn; FL_OBJECT *BlockingAckWModeCheckbtn; FL_OBJECT *WIntervalCheckbtn; FL_OBJECT *WIntervalRedCheckbtn; FL_OBJECT *StartBtn; FL_OBJECT *ExitBtn; } FD_MainForm;/* Form for display of simulation progress */typedef struct { FL_FORM *VisForm; void *vdata; char *cdata; long ldata; IndicatorType *Indicator; FL_OBJECT *StopBtn; } FD_RunForm; /* Form for display of simulation results */typedef struct { FL_FORM *VisForm; } FD_ResultsForm;/* Structure of shared memory segment used for communicating the simulation results between wirte/read processes and the split and main process. */ typedef struct { int result; unsigned long rw[EIB_BUF_ELEMENT_SIZE]; // Number of successful and unsigned long w_failed[EIB_BUF_ELEMENT_SIZE]; // failed read and writes unsigned long tp; // Total penalty time in } Eib_bcu2_sim_shm; // reduced write interval mode/* All settings of the eibdrv driver that can be requested by a user program. */ typedef struct { int mode; // Standard/Server mode of driver int symb_baudrate; // symbolic constant of baudrate char *port; // serial port unsigned long outbuf_size; // outgoing messages (writes) unsigned long wpbuf_size; // writing processes unsigned long rpbuf_size; // reading processes unsigned long rpbuf_msgbuf_size; // incoming messages (reads) } Eib_bcu2_settings;/* All parameter of the simulation current configured in the main form. */ typedef struct { int run_time; // Run time of all read and write processes int write_interval; // Time interval within msg are written randomly int min_len; // Minimal value for random message length int max_len; // Maximal value for random message length int proc_count; // Number of write/read processes to be forked int wmode; // Blocking, nonblocking or acknowledged write int winterval; // W or w/o penalty reduction of write time interval } Eib_bcu2_sim_parameter; /* Structure of the simulator */ typedef struct { FD_MainForm *MainForm; // Main form FD_RunForm *RunForm; // Progress visualization form PanelContent *Panels; // Message panels char *device; // Device string int f_stop_readwrite; // Flag for run timeout of write/read processes int state; // Internal state of simulator time_t start_time; // Simulation start time time_t last_act_time; // Time of last indicator actualization int eib_fd; // Filedescriptor for driver FILE *log_fd; // Filedescriptor for logfile Eib_bcu2_settings *ftstation_settings; // Driver settings Eib_bcu2_sim_parameter *act_parameter; // Parameter set in main form Eib_bcu2_sim_parameter *sim_parameter; // Parameter for simulation Eib_statistics *stat; // Driver statistics after simulation run time_t stat_reset_time; // Time since last statistics reset time_t stat_get_time; // Time since last statistics actualization pid_t split_pid; // Process-ID of read/write-generating process int cleanup_code; // Abort of program int shm_results_id; // ID of shared memory for results Eib_bcu2_sim_shm *shm_results; // Shared memory for results int sem_shm_results; // sem synchronizing access to result shm int sem_start_rw; // sem synchronizing start of read/writes } Eib_bcu2_sim;/* Structure of read/write processes */typedef struct { int eib_fd; // Filedescriptor for driver Eib_bcu2_sim_shm *shm_segment; // Segment in shm for process results Eib_bcu2_sim_shm local_results; // Local results } Eib_bcu2_sim_rw; Eib_bcu2_sim *sim; // Central simulator struct used by all processesEib_bcu2_sim_rw rw_sim; // Read/write process struct int baudrates[18][2]={ {B50,50}, // Table of symbolic baudrates and their integer {B75,75}, // value {B110,110}, {B134,134}, {B150,150}, {B200,200}, {B300,300}, {B600,600}, {B1200,1200}, {B1800,1800}, {B2400,2400}, {B4800,4800}, {B9600,9600}, {B19200,19200}, {B38400,38400}, {B57600,57600}, {B115200,115200}, {B230400,230400}};/* --------------------------------------------------------------------------- Various function prototypes. ---------------------------------------------------------------------------*/void cleanup(void *arg,int btn);void panel_cb(void *arg,int btn);void sim_split();void main_sigchld_handler();void StopBtn_cb(FL_OBJECT *obj,long data);/* --------------------------------------------------------------------------- Allocation and deallocation of simulator data structures, --------------------------------------------------------------------------- */Eib_bcu2_sim *getEib_bcu2_sim(){ Eib_bcu2_sim *help=(Eib_bcu2_sim *)fl_calloc(1,sizeof(Eib_bcu2_sim)); help->MainForm=NULL; help->RunForm=NULL; help->Panels=NULL; help->state=EIBDRV_SIM_STATE_INIT; help->ftstation_settings=(Eib_bcu2_settings *)fl_calloc(1,sizeof(Eib_bcu2_settings)); help->ftstation_settings->port=NULL; help->act_parameter=(Eib_bcu2_sim_parameter *)fl_calloc(1,sizeof(Eib_bcu2_sim_parameter)); help->sim_parameter=(Eib_bcu2_sim_parameter *)fl_calloc(1,sizeof(Eib_bcu2_sim_parameter)); help->stat=(Eib_statistics *)fl_calloc(1,sizeof(Eib_statistics)); help->cleanup_code=0; return help;}void returnEib_bcu2_sim(Eib_bcu2_sim *sim){ free(sim->MainForm); free(sim->RunForm); returnPanelContentA(sim->Panels,EIBDRV_SIM_PANELFILESIZE); if (sim->ftstation_settings->port!=NULL) free(sim->ftstation_settings->port); free(sim->ftstation_settings); free(sim->act_parameter); free(sim->sim_parameter); free(sim->stat); free(sim->device); free(sim);}/* This function delays the caller process for usec Mikroseconds by blocking it. */ void delay(unsigned long usec){ struct timeval timeout; if (usec==0) return; timeout.tv_sec=usec / 1000000L; timeout.tv_usec=usec % 1000000L; select(0,NULL,NULL,NULL,&timeout);}/* This function modifies the Text1 variable of the given panel structure to display a given error_code in the message text of a message panel. */ void make_InternalErrorPanel(PanelContent *panel,int error_code){ char helpstring[40]; if (panel==NULL) return; sprintf(&helpstring[0],"Internal error %i occured!",error_code); free(panel->Text1); panel->Text1=(char *)malloc((strlen(&helpstring[0])+1)*sizeof(char)); strcpy(panel->Text1,&helpstring[0]);} /* --------------------------------------------------------------------------- Creation of all forms and callbacks of all visual elements. --------------------------------------------------------------------------- */ char *get_wmode_text(int wmode){ switch(wmode) { case EIBDRV_SIM_NONBLOCKSTDWMODE: return "Nonblocking Standard"; case EIBDRV_SIM_BLOCKSTDWMODE: return "Blocking Standard"; case EIBDRV_SIM_NONBLOCKACKWMODE: return "Nonblocking Acknowledged"; case EIBDRV_SIM_BLOCKACKWMODE: return "Blocking Acknowledged"; } return NULL;}char *get_winterval_text(int winterval){ switch(winterval) { case EIBDRV_SIM_INTERVAL: return "Without penalty reduction"; case EIBDRV_SIM_REDINTERVAL: return "With penalty reduction"; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -