” 写作CSCI 463语言、 辅导ASCII编程、 写作C/C++程序设计CSCI 463 Assignment 6 RISC-V Multithreading20 Points Due Friday, December 4, 2020 at 23:59AbstractIn this assignment, you will create a producer-consumer application that will run on an RV32I simulatorbased on a multithreaded example called mt01 as presented in lecture.1 Problem DescriptionSend a series of ASCII messages from a producer thread to a consumer thread by using an eight-byte lock-freequeue as discussed in lecture.2 Files You Must WriteYou will write a C Program suitable for execution on the RV32I simulator installed on hopper.cs.niu.edu(or turing.cs.niu.edu.)Your source file(s) MUST be named exactly as shown below or they will fail to compile and you will receivezero points for this assignment.Start by copying the mt01 example application (and other examples and Makefiles) from this directory onhopper.cs.niu.edu as shown below:cp -r /home/hopper/winans/463/rv32i/examples .As described, this cp command will copy the entire tree of example files into the directory where you ranthe cp command into a new directory called examples.Within these example files, you will find a directory named mt01 as seen in lecture.You will not need to create any new files for this assignment. You will implement this assignment by editingthe main.c file in the mt01 example.2.1 Alterations to main.cppAs provided, the mt01 example application configures two harts to call main() where one hart executes theproducer() function and a second executes the consumer() function where the producer sends a 26-bytemessage to the Consumer.You will alter the program so that it will send an arbitrary number of variable-length ASCII text stringmessages from the producer to the consumer.2.1.1 main()Change your main() so that hartid zero will call producer() seven times to send the following text strings:111111111111Hello out thereaaaaaaaaaaaaaCopyright 2020 John Winans. All Rights Reserved~/NIU/courses/463/2020-fa/assignments/a6/handout.texjwinans@niu.edu 2020-12-01 15:08:27 -0600 v2.0-823-g1df089ePage 1 of 5CSCI 463 Assignment 6 RISC-V Multithreadingbbbbbbbbbbbccc1234\03 // Note: this is how you can create a string that contains an ETX character.Note that character code three \03 is the ASCII ETX character (which stands for End Of Text.) We willuse it to Determine that the producer has finished sending messages.Change your main() so that hartid one will call consumer() in a loop until the consumer has received amessage string with the value \03.2.1.2 producer(const char *msg)Your producer will accept a parameter that is a character pointer to a C string (a series of characters followedby a null-character that terminates the string.) You may assume that the string will never be be too long.The producer must send each string and its null-terminator to the consumer and return.The producer must be written such that it can be called once for each ASCII message that is to be sent.2.1.3 consumer()The consumer must be written such that it can be called once for each ASCII message that is to be received.Each message must be saved in an array named consumer_buffer, including the null-terminator, after anyprevious messages such that all of them will remain in the consumer buffer, one after the other, after thesimulation has terminated.2.1.4 consumer bufferChange the definition of consumer buffer to this:char* consumer_buffer = (char *)0x00005000;Doing so will tell the compiler to use the memory starting at address 0x00005000 as the consumer buffer(as opposed to letting the compiler and/or linker decide where to put it.) Note that writing to this regionof memory Will clobber anything that might otherwise be there. Make sure to use nm -n prog to make surethat your code, data, and BSS does not grow that high and these two overlap! (If they do, you are likelydoing something very wrong.My solution shows the _end at 00002abc as seen below:$ nm -n prog…00002ab0 B buffer00002ab8 B errno00002abc B __BSS_END__00002abc B _endYour Program will likely not end in the exact same spot as each solutions code (and thus number ofinstructions) is likely to be different. However, they should not differ by multiple kilobytes. So using0x00005000 should be OK.Copyright 2020 John Winans. All Rights Reserved~/NIU/courses/463/2020-fa/assignments/a6/handout.texjwinans@niu.edu 2020-12-01 15:08:27 -0600 v2.0-823-g1df089ePage 2 of 5CSCI 463 Assignment 6 RISC-V Multithreading3 OutputYour program will be tested by running it and checking to see if the proper values are stored into theconsumers buffer at address 0x00005000 in the memory dump at the end of your program run and by spotchecking the values of other variables like ppos, cpos, and buffer.Running nm on my reference solution includes the following information:$ nm -n prog…00002a74 S cpos00002a78 S ppos…00002ab0 B buffer…The post-simulation Dump from my reference solution incluides with the following values:make run…00002a70: 42 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 *B……………*00002a80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 *…………….*00002a90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 *…………….*00002aa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 *…………….*00002ab0: 03 00 00 31 32 33 34 00 00 00 00 00 a5 a5 a5 a5 *…1234………*00002ac0: a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 *…………….*…00004ff0: a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 *…………….*00005000: 31 31 31 31 31 31 31 31 31 31 31 31 00 48 65 6c *111111111111.Hel*00005010: 6c 6f 20 6f 75 74 20 74 68 65 72 65 00 61 61 61 *lo out there.aaa*00005020: 61 61 61 61 61 61 61 61 61 61 00 62 62 62 62 62 *aaaaaaaaaa.bbbbb*00005030: 62 62 62 62 62 62 00 63 63 63 00 31 32 33 34 00 *bbbbbb.ccc.1234.*00005040: 03 00 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 *…………….*00005050: a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 a5 *…………….*…4 How To Hand In Your ProgramWhen you are ready to turn in your assignment, make sure that the only files in your edited mt01 directoryis/are the source files defined and discussed above. Then, in the parent of your mt01 directory, use themailprog.463 command to send the contents of the files in your version of the mt01 project directory in thesame manner as we have used in the past.5 GradingThe grade you receive on this programming assignment will be scored according to the syllabus and itsability to compile and execute on the Computer Science Departments computer.It is your Responsibility to test your program thoroughly.Copyright 2020 John Winans. All Rights Reserved~/NIU/courses/463/2020-fa/assignments/a6/handout.texjwinans@niu.edu 2020-12-01 15:08:27 -0600 v2.0-823-g1df089ePage 3 of 5CSCI 463 Assignment 6 RISC-V MultithreadingWhen we grade your assignment, we will compile it on hopper.cs.niu.edu by using ONLY your main.cfile and original copies of the other mt01 example program source and Makefile files. In other words, makeSURE that you save and test your final program with all the other original files from the mt01 example files.(Keep backup files so you dont clobber your work when making copies of things!)6 HintsAs always, build up a solution one step at a time. Multithreaded programs can be VERY difficult to thinkabout. Take VERY SMALL steps! It is likely that this assignment is impossible to complete without watching the related course lecturesfirst. If you have not yet done so then watch them now! Start by making sure that you can run the mt01 example as seen in lecture. If it does not work thensomething is wrong and you can not proceed. Try checking your copy of the example files and thatyou have the mt01 files AS WELL as the Makefile and Make.rules files in the parent directory. (Itis easiest to take all the files and examples as shown above and in lecture.) Note that your producer must be written such that it can be called from main multiple times! If/whenproducer() is called a second, thjird,… time, it must pick up by using the ppos value where it leftoff from the last time producer() was called. In order words, you DONT want to reset it norclear the buffer when producer() is called. (Remember that ppos and cpos are also used by theconsumer!) Note that the producer has to send all the characters in the text string INCLUDING its null-terminatingcharacters. Otherwise the consumer will not know where the end(s) of each text message(s) is/are.There are multiple ways to do this:1. Set a flag in the loop when it sends the null-character from the given msg parameter such thatthe flag terminates your sending loop and the function returns.2. Count the number of characters in the string (including the null-terminator) and then send thatnumber of characters from the given msg parameter. Note that your consumer must be made such that it can be called from main() multiple times! Likethe producer, note that it does not matter where cpos is when your consumer() is finished. Theimportant thing Here is that if/when consumer() is called again, it must pick up by using the cposvalue where it left off from the last time it was called. Again, you dop not waht to reset cpos orppos. Note that the consumer must read one string at a time from the producer. To do so, it must readall the characters until it reaches a null-terminator character (and store the null-terminator into theconsumer_buffer too) and then return. I found the easiest way for me to do this was to set a flag in theconsumers reading loop that terminates said loop after it has received and stored the null-terminatorcharacter into the consumer_buffer. Recall that this is a C program. You probably want to use functions like strlen() and strcmp()when working with C strings. It is now tougher to stop the simulator any time you want to because, while you can halt one hartwith an ebreak instruction, the other might continue on indefinitely.You might have to experiment with the max instruction limit if you are completely in trouble.Copyright 2020 John Winans. All Rights Reserved~/NIU/courses/463/2020-fa/assignments/a6/handout.texjwinans@niu.edu 2020-12-01 15:08:27 -0600 v2.0-823-g1df089ePage 4 of 5CSCI 463 Assignment 6 RISC-V Multithreading Consider running your program with only one hart and send short (1-character) messages until youcan see that your producer is filling in the buffer and managing its ppos variable perfectly before yourun with two harts and proceed to working on your consumer. Recall that you can send one or twosmall messages and let your producer return and halt so that you can get your simulator to halt whilefocusing on sending those one or two messages in your consumer and checking that the producer() isworking perfectly before trying to debug two threads at once.You can also start your application with cpos and ppos set to any starting values desires as long asthey both start With the same value. Consider how this might help verify your producer is operatingproperly when testing this one-hart scenario.Note that with only one hart running, you can halt it any time you want by placing an ebreakinstruction anywhere desired by using an inline assembler instruction as seen in lecture. (See theexit() function in stub stdlib.c for an example how to do this.) Recall that if you create a test case where your producer never reaches the end of the buffer (like ifit only sends two one-byte messages), that it will enqueue those messages without ever blocking andthen it will return and halt.When in this state, the consumer might still be running to read the messages that the producer hasplaced into the buffer. . . and if you have already perfected your producer and know it has halted, thenyou can toss in an ebreak instruction using inline assembler as seen in lecture to stop your consumeranywhere you want. There are many ways to figure out if a message containing ETX (aka \03) has arrived or not. I proposethat you keep track of the next byte to fill index of the consumer_buffer in a global variable thatis used and advanced in your consumer() function so that the code in main() can know where it isafter consumer() returns. . . so you can know where to look and see if the last message was an \03.Recall that \03 is a two bytes with the values 0x03 and 0x00.Checking if the last message is an 0x03 and a 0x00 has to be done carefully. Make sure that youfirst check if the consumer_buffer has at least two bytes in it before you decide to blindly look at avalue. . . such as consumer_buffer[next_byte_to_fill – 2].7 Stuff You Should Know What sort of maximum limit do you suppose is reasonable for the length of any one message that ispassed to Producer(const char *msg) for sending? How many total messages can we send with this application? What sum-total number of message bytes can this application send? What Would happen if this program is executed with only one hart and why? What would happen if this program is executed with three or more harts and why?Copyright 2020 John Winans. All Rights Reserved~/NIU/courses/463/2020-fa/assignments/a6/handout.texjwinans@niu.edu 2020-12-01 15:08:27 -0600 v2.0-823-g1df089e如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。