1 / 17

FIFO’s, which are named pipes

FIFO’s, which are named pipes. Process 1 void main() { mknod(“/tmp/myfifo”, S_IFIFO, ); // create a FIFO file node f = open(“/tmp/myfifo”, O_WRONLY); while (1) {generate_data(buf); write(q, buf, n);} } Process 2 void main() { f = open(“/tmp/myfifo”, O_RDONLY);

anne
Download Presentation

FIFO’s, which are named pipes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FIFO’s, which are named pipes • Process 1 void main() { mknod(“/tmp/myfifo”, S_IFIFO, ); // create a FIFO file node f = open(“/tmp/myfifo”, O_WRONLY); while (1) {generate_data(buf); write(q, buf, n);} } • Process 2 void main() { f = open(“/tmp/myfifo”, O_RDONLY); while (1) {read(q, buf, n); process_data(buf);} } • Works for “unrelated” processes • Multiple writers, Multiple readers • Kernel ensures mutual exclusion • Kernel does not control interleaving of writers, readers CSE 466 – Fall 2000 - Introduction - 1

  2. Impement a FIFO w/ a Device Driver CSE 466 – Fall 2000 - Introduction - 2

  3. Reentrant Driver problem: processes added to wq after wake_on may never get awakened! They have to wait until a read is attempted after the queue is emptied and INIT is turned off. read() { if (INIT) sleep_on(wq); else start = getTime(); INIT = 1; sleep_on(wq); compute_distance(); copy_to_user(); if (empty(wq)) INIT = 0; return; } isr() { stop = getTime(); wake_on(wq); INIT = 0; } open() { if (count++) return; else grab_resources(); } release() { if (--count) return; else release_resources(); } read() { if (INIT) sleep_on(wq); else start = getTime(); INIT = 1; sleep_on(wq); compute_distance(); copy_to_user(); if (empty(wq)) INIT = 0; return; } isr() { stop = getTime(); wake_on(wq); } still: a new read that occurs while before the queue is emptied will overwrite “start” CSE 466 – Fall 2000 - Introduction - 3

  4. Use a Bottom Half! read() { if (INIT) sleep_on(wq); else start = getTime(); INIT = 1; sleep_on(wq); compute_distance(); copy_to_user(); if (empty(wq)) INIT = 0; return; } isr() { // reads will still pile up on the wait queue until the bh executes. stop = getTime(); add_to_bh_queue(isr_bh); } isr_bh() { // make a new queue for all future reads, compute distance with correct start-stop data. sonar_result = Compute_distance(); INIT = 0; tmp = wq; wq = (wait_queue*) kmalloc(sizeof(wait_queue)); wake_on(tmp); } will each reader get the “correct” reading? do we care? CSE 466 – Fall 2000 - Introduction - 4

  5. Fuel Cell Power Plant A Control Dominated Example • controller • sense: • Temperature • H2 • Output Current • Output Voltage • Fan Speed • control • H2 valves • Output MOSFET • Fan Speed • Stack MOSFETS Air H2 Heat H20 not showing power supply circuitry for the controller…runs off fuel cell w/ backup battery. CSE 466 – Fall 2000 - Introduction - 5

  6. System level Modes (Logical Structure) warmup online startup Self Check Pass Failure Warm On Failure Off+ V<min + I>max shtdwn Self Check Fail offline I>0+V<min off Failure = H2+TooHot+TooCold CSE 466 – Fall 2000 - Introduction - 6

  7. Mode Outputs Processes Events New Mode Off Load Disabled Power Supply Off Gas Valves Closed Power Button Enabled none Power Button Push Startup Startup Load Disabled Power Supply On Gas Valves Closed Initialize Temp Control H2 Detection Load Monitor UI Running Initialize Complete Warm Up Error Condition Detected* or shutdown request Shutdown Warmup Load Disabled Power Supply On Gas Valves Open Temp Control H2 Detection Load Monitor UI Running Operating Temp Reached Off Line Error Condition Detected* or shutdown request Shutdown Off Line Load Disabled Power Supply On Gas Valves Open Temp Control H2 Detection Load Monitor UI Running On-Line Command Received (UI) On Line Error Condition or Shutdown request Shutdown On Line Load Enabled Power Supply On Gas Valves Open Temp Control H2 Detection Load Monitor UI Running Off Line Command Off Line Overload Off Line Error Condition* or Shutdown Request Shutdown Shutdown Load Disabled Power Supply On Gas Valves Closed Fan On Temp Control Schedule transition to Off state Timeout Off State Table (activities/error conditions are mode dependent) CSE 466 – Fall 2000 - Introduction - 7

  8. Examples of Mode Dependencies • Fan Speed Control: • In startup or shutdown mode always run minimum speed • otherwise attempt to maintain temperature set point • If fan doesn’t turn, issue shutdown event • Hydrogen Detection: always close hydrogen valves and issue shutdown event if hydrogen detected, except in startup mode. • Load Monitoring • If not online and output current > 0 or output voltage < min, then issue shutdown event. • If online and load current is > max allowed, or if output voltage is < min then turn on another stack. If all stacks are on, then issue overload event. • UI Process • If “line” button pushed and online issue offline event, If offline issue online event. • If “power” button pushed and not in off mode, then issue shutdown event. CSE 466 – Fall 2000 - Introduction - 8

  9. Master Slave Architecture • Master/Slave Architecture • master process: determines what mode the system is in at any given time and synchronizes mode transitions. Process events and data. • Slave processes: Perform mode-dependent activities, pass data and events back to master. • Logical Decomposition Master (UI) commands responses Slave 1 (H2) Slave 2 (Load) Slave 3 (Temp) CSE 466 – Fall 2000 - Introduction - 9

  10. Sockets are a “logical” constructs Socket could be implemented in shared memory, internet, or anything in between. High level architecture can be independent of implementation choices. Synthesis Problem: Map processes and sockets to processors and networks Warning: usually not done this way for embedded systems…usually designer performs the physical decompositions socket == 2-way fifo slave Master slave slave CSE 466 – Fall 2000 - Introduction - 10

  11. Master/Slave Software Architecture Master void master() _task_ MAST{ Button(mode); // enq(cmd) checkDB(mode); // enq(cmd) } void comTop() _task_ COM{ wait(K_TMO, 1); if (!deq(cmd)) { cmd = pollCmd(next++); slave = next; } else slave = toWho(cmd); write(slave, cmd); read(response); signal(VERIFY); } void comBot() _task_ VERIFY{ // match up resp. and commds wait(K_SIG); verify(response); updateDB(response); } commands and responses are packets not single bytes mode is NOT a global variable Slave void mainTask() _task_ SL{ manageLoad(mode); } void comTop() _task_ TOP{ read(master,cmd); write(master,response); //prev signal(DO); }// could be ISR void comBot() _task_ DO { wait(K_SIG); response = do(cmd); // set local mode } COMMANDS RESPONSES responses are for previous command CSE 466 – Fall 2000 - Introduction - 11

  12. slave slave Distributed State Synchronization manageLoad() { db[V] = readV(); db[I] = readI(); adjustStack(I,V); } do(cmd) { if (cmd=OFF) { out = 0; db[M] = offline; } if (cmd=ON) out = 1; db[M] = online; } return(makeR(db[i++])); } is there a problem here? Master Button() {… if (LineButton && offline) { enq(OFF); offline = true; } checkDB() { if (offline && db[I]>0) enq(SHT); } SHT, OFF, POLL, POLL I=10,V=15, M=ON, I=0 CSE 466 – Fall 2000 - Introduction - 12

  13. Synchronous Systems online offline offline warmup propagation time need to identify mode transition periods, and identify data that is out of synch as a result of transition. Need also to know when it is valid again. CSE 466 – Fall 2000 - Introduction - 13

  14. Managing Distributed Transitions manageLoad() { db[V] = readV(); db[I] = readI(); adjustStack(I,V); } do(cmd) { if (cmd=OFF) { out = 0; db[M] = offline; } if (cmd=ON) out = 1; db[M] = online; } return(makeR(db[i++])); } Master Button() {… if (LineButton && offline) { enq(OFF); offline = true; } checkDB() { if (offline&&VLD(db[I])&&db[I]>0) enq(SHT); } enq(cmd) { if (cmd=OFF) { db[I] = INVLD; db[V] = INVLD; db[M] = INVLD; q.data[q.head] = cmd; next(q); } updateDB(response) { ignore slave responses until correct mode is received from slave } db’s are not global either! POLL,POLL,POLL,POLL, OFF, POLL, POLL I=10,V=15, M=ON, I=5, V=20, M=OF, I=0 ignored, transition period could improve transition speed by advancing i to M in do(). Also need to be concerned with physical time lag from !out CSE 466 – Fall 2000 - Introduction - 14

  15. Multiprocessor Implementation Bus Two main types of serial buses: master/slave (SPI,USB) and multi-master (I2C, CAN) CSE 466 – Fall 2000 - Introduction - 15

  16. CSE 466 – Fall 2000 - Introduction - 16

  17. Physical Partition – the network CSE 466 – Fall 2000 - Introduction - 17

More Related