/* Basic setup is the same as in the single-threaded example. However, * we do some thread initiliazation first before invoking the job. */ int main(int argc, char** argv) { int i; struct thread_context ctx[NUM_THREADS]; pthread_t task[NUM_THREADS]; /* The task is in background mode upon startup. */ /***** * 1) Command line paramter parsing would be done here. */ /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ /***** * 3) Initialize LITMUS^RT. * Task parameters will be specified per thread. */ init_litmus(); /***** * 4) Launch threads. */ for (i = 0; i < NUM_THREADS; i++) { ctx[i].id = i; pthread_create(task + i, NULL, rt_thread, (void *) (ctx + i)); } /***** * 5) Wait for RT threads to terminate. */ for (i = 0; i < NUM_THREADS; i++) pthread_join(task[i], NULL); /***** * 6) Clean up, maybe print results and stats, and exit. */ return 0; }
int main(int argc, char** argv) { int ret; int opt; int wait = 0; int test_loop = 0; int skip_config = 0; int verbose = 0; double wcet_ms; double duration, start; struct rt_task rt; FILE *file; progname = argv[0]; while ((opt = getopt(argc, argv, OPTSTR)) != -1) { switch (opt) { case 'w': wait = 1; break; case 'l': test_loop = 1; break; case 'd': /* manually configure delay per loop iteration * unit: microseconds */ loop_length = atof(optarg) / 1000000; skip_config = 1; break; case 'v': verbose = 1; break; case ':': usage("Argument missing."); break; case '?': default: usage("Bad argument."); break; } } if (!skip_config) configure_loop(); if (test_loop) { debug_delay_loop(); return 0; } if (argc - optind < 2) usage("Arguments missing."); if ((file = fopen(argv[optind + 0], "r")) == NULL) { fprintf(stderr, "Cannot open %s\n", argv[1]); return -1; } duration = atof(argv[optind + 1]); memset(&rt, 0, sizeof(struct rt_task)); if (parse_hime_ts_file(file, &rt) < 0) bail_out("Could not parse file\n"); if (sporadic_task_ns_semi(&rt) < 0) bail_out("could not setup rt task params"); fclose(file); if (verbose) show_loop_length(); init_litmus(); ret = task_mode(LITMUS_RT_TASK); if (ret != 0) bail_out("could not become RT task"); if (wait) { ret = wait_for_ts_release(); if (ret != 0) bail_out("wait_for_ts_release()"); } wcet_ms = ((double) rt.exec_cost ) / __NS_PER_MS; start = wctime(); while (start + duration > wctime()) { job(wcet_ms * 0.0009); /* 90% wcet, in seconds */ } return 0; }
int main(int argc, char *argv[]) { AVFormatContext *pFormatCtx = NULL; int i, videoStream; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVFrame *pFrame = NULL; AVFrame *pFrameRGB = NULL; AVPacket packet; int frameFinished; int numBytes; uint8_t *buffer = NULL; AVDictionary *optionsDict = NULL; struct SwsContext *sws_ctx = NULL; // Real-Time Setup int do_exit; int count = 0; /* rt_task defined in rt_param.h struct rt_task { lt_t exec_cost; lt_t period; lt_t relative_deadline; lt_t phase; unsigned int cpu; unsigned int priority; task_class_t cls; budget_policy_t budget_policy; release_policy_t release_policy; */ struct rt_task param; /* Setup task parameters */ init_rt_task_param(¶m); param.exec_cost = ms2ns(EXEC_COST); param.period = ms2ns(PERIOD); param.relative_deadline = ms2ns(RELATIVE_DEADLINE); /* What to do in the case of budget overruns? */ param.budget_policy = NO_ENFORCEMENT; /* The task class parameter is ignored by most plugins. */ param.cls = RT_CLASS_SOFT; /* The priority parameter is only used by fixed-priority plugins. */ param.priority = LITMUS_LOWEST_PRIORITY; /* The task is in background mode upon startup. */ // END REAL TIME SETUP /***** * 1) Command line paramter parsing would be done here. */ if(argc < 2) { printf("Please provide a movie file\n"); return -1; } /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ // Register all formats and codecs av_register_all(); // Open video file if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0) return -1; // Couldn't open file // Retrieve stream information if(avformat_find_stream_info(pFormatCtx, NULL)<0) return -1; // Couldn't find stream information // Dump information about file onto standard error av_dump_format(pFormatCtx, 0, argv[1], 0); /***** * End Work Environment Setup */ // Find the first video stream videoStream=-1; for(i=0; i<pFormatCtx->nb_streams; i++) if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) { videoStream=i; break; } if(videoStream==-1) return -1; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx->streams[videoStream]->codec; // Find the decoder for the video stream pCodec=avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec==NULL) { fprintf(stderr, "Unsupported codec!\n"); return -1; // Codec not found } // Open codec if(avcodec_open2(pCodecCtx, pCodec, &optionsDict)<0) return -1; // Could not open codec // Allocate video frame pFrame=av_frame_alloc(); // Allocate an AVFrame structure pFrameRGB=av_frame_alloc(); if(pFrameRGB==NULL) return -1; // Determine required buffer size and allocate buffer numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); sws_ctx = sws_getContext ( pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL ); // Assign appropriate parts of buffer to image planes in pFrameRGB // Note that pFrameRGB is an AVFrame, but AVFrame is a superset // of AVPicture avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); /***** * 3) Setup real-time parameters. * In this example, we create a sporadic task that does not specify a * target partition (and thus is intended to run under global scheduling). * If this were to execute under a partitioned scheduler, it would be assigned * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); // Defined in litmus.h /* To specify a partition, do * * param.cpu = CPU; * be_migrate_to(CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1 before calling * set_rt_task_param(). */ CALL( set_rt_task_param(gettid(), ¶m) ); // Defined in litmus.h /***** * 4) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); // Defined in litmus.h /* The task is now executing as a real-time task if the call didn't fail. */ // Read frames and save first five frames to disk i=0; while(av_read_frame(pFormatCtx, &packet)>=0) { /* Wait until the next job is released. */ sleep_next_period(); // Print frame number printf("Frame %d\n", i); // Is this a packet from the video stream? if(packet.stream_index==videoStream) { // Decode video frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); // Did we get a video frame? if(frameFinished) { // Convert the image from its native format to RGB sws_scale ( sws_ctx, (uint8_t const * const *)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize ); // Save the frame to disk if(++i<=5) SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i); } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); } /***** * 6) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); // Free the RGB image av_free(buffer); av_free(pFrameRGB); // Free the YUV frame av_free(pFrame); // Close the codec avcodec_close(pCodecCtx); // Close the video file avformat_close_input(&pFormatCtx); /***** * 7) Clean up, maybe print results and stats, and exit. */ return 0; }
int main(int argc, char** argv) { int i; long j; struct thread_context *ctx; pthread_t *task; FILE *f; char path[200]; exit_program = 0; count_first = 0; threads = atoi(argv[1]); interrupter = atoi(argv[2]); cpus = atoi(argv[3]); executions = atoi(argv[4]); helping = atoi(argv[5]); locking = atoi(argv[6]); scheduling = atoi(argv[7]); measure = atoi(argv[8]); push = atoi(argv[9]); non_preemption = atoi(argv[10]); init_litmus(); be_migrate_to_domain(1); ctx = malloc(sizeof(struct thread_context) * threads); task = malloc(sizeof(pthread_t) * threads); /* init arrays */ for (i = 0; i < threads; i++) { ctx[i].response_time = malloc(sizeof(long long) * executions); for (j = 0; j < executions; j++) { ctx[i].response_time[j] = 0; } } /* init and create tasks */ for (i = 0; i < threads; i++) { ctx[i].id = i + 1; ctx[i].execute_count = 0; if (ctx[i].id < interrupter) { ctx[i].priority = 500; ctx[i].cpu = ctx[i].id; } else { ctx[i].priority = 5; ctx[i].cpu = ctx[i].id - cpus; } pthread_create(task + i, NULL, rt_thread, (void *) (ctx + i)); } for (i = 0; i < threads; i++) pthread_join(task[i], NULL); /* open the right file */ if(measure == 0) strcpy(path, "../cs/"); if(measure == 1) strcpy(path, "../ml/"); if(measure == 2) strcpy(path, "../rt/"); if (scheduling == 1) strcat(path, "result_pull/"); if (scheduling == 3) strcat(path, "result_push/"); if (scheduling == 2) strcat(path, "result_swap/"); if (scheduling == 4) strcat(path, "result_challenge/"); if (threads == 1 && locking == 7) strcat(path, "mrsp1.txt"); if (threads == 2 && locking == 7) strcat(path, "mrsp2.txt"); if (threads == 3 && helping == 1 && locking == 7) strcat(path, "mrsp31.txt"); if (threads == 3 && helping == 0 && locking == 7) strcat(path, "mrsp30.txt"); if (threads == 4 && helping == 1 && locking == 7) strcat(path, "mrsp41.txt"); if (threads == 4 && helping == 0 && locking == 7) strcat(path, "mrsp40.txt"); f = fopen(path, "w"); if (f == NULL) { printf("Error opening result file!\n"); } /* write time to the file */ printf("threads %d, helping %d, measure %d, scheduling %d, goes to file %s.\n", threads, helping, measure, scheduling, path); for (i = 0; i < threads; i++) { sum = 0; fprintf(f, "task %d access time:\n", i + 1); for (j = 0; j < executions; j++) { if (ctx[i].response_time[j] != 0) { sum += ctx[i].response_time[j]; fprintf(f, "%lld\n", ctx[i].response_time[j]); } else break; } avg = sum /j; if (avg != 0) { printf("task %d on core %d executes %ld times, exec_avg1: %20.5f\n", i, ctx[i].cpu, j, avg); fprintf(f, "task %d on core %d executes %ld times, exec_avg1: %20.5f\n", i, ctx[i].cpu, j, avg); } free(ctx[i].response_time); } fclose(f); free(ctx); free(task); return 0; }
int main(int argc, char** argv) { int do_exit, ret; struct rt_task param; sprintf(myPID,"%d",getpid()); strcat(filePath,myPID); //argv 1. wcet(ms) 2. period(ms) 3. duration(s) 4. mode (1 for cali sar, 4 for cali kalman) 5. appName 6. size/iter wcet_f = atoi(argv[1]); // in ms period_f = atof(argv[2]); // in ms size_iter = atof(argv[6]); wcet_us = (int)(wcet_f*1000); // Convert ms to us // wcet_frac = modf(wcet_f,&int_temp); // wcet_int = (int)(int_temp); dur = 1000 * atoi(argv[3]); // in seconds -> to ms mode = atoi(argv[4]); count = (dur / period_f); // printf("wcet_f: %f\tperiod_f: %f\twcet_us: %ld\tcount: %d\n", // wcet_f,period_f,wcet_us,count); if(argc > 6) { strncpy(myName,argv[5],40); } else { strncpy(myName,"NoNameSet",40); } printf("Name set: %s\n",myName); /* Setup task parameters */ memset(¶m, 0, sizeof(param)); // param.exec_cost = wcet_f * NS_PER_MS; // param.period = period_f * NS_PER_MS; param.exec_cost = wcet_f * NS_PER_MS; param.period = period_f * NS_PER_MS; // printf("param.exec: %ld\tparam.period: %ld\n",param.exec_cost, param.period); // return 0; param.relative_deadline = period_f * NS_PER_MS; /* What to do in the case of budget overruns? */ param.budget_policy = NO_ENFORCEMENT; /* The task class parameter is ignored by most plugins. */ param.cls = RT_CLASS_SOFT; param.cls = RT_CLASS_HARD; /* The priority parameter is only used by fixed-priority plugins. */ param.priority = LITMUS_LOWEST_PRIORITY; /* The task is in background mode upon startup. */ /***** * 1) Command line paramter parsing would be done here. */ /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ /***** * 3) Setup real-time parameters. * In this example, we create a sporadic task that does not specify a * target partition (and thus is intended to run under global scheduling). * If this were to execute under a partitioned scheduler, it would be assigned * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); /* To specify a partition, do * * param.cpu = CPU; * be_migrate_to(CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1 before calling * set_rt_task_param(). */ CALL( set_rt_task_param(gettid(), ¶m) ); /***** * 4) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); /* The task is now executing as a real-time task if the call didn't fail. */ pCtrlPage = get_ctrl_page(); ret = wait_for_ts_release(); if (ret != 0) printf("ERROR: wait_for_ts_release()"); /***** * 5) Invoke real-time jobs. */ do { /* Wait until the next job is released. */ sleep_next_period(); /* Invoke job. */ do_exit = job(); } while (!do_exit); /***** * 6) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); /***** * 7) Clean up, maybe print results and stats, and exit. */ return 0; }
/* typically, main() does a couple of things: * 1) parse command line parameters, etc. * 2) Setup work environment. * 3) Setup real-time parameters. * 4) Transition to real-time mode. * 5) Invoke periodic or sporadic jobs. * 6) Transition to background mode. * 7) Clean up and exit. * * The following main() function provides the basic skeleton of a single-threaded * LITMUS^RT real-time task. In a real program, all the return values should be * checked for errors. */ int main(int argc, char** argv) { int do_exit; /* The task is in background mode upon startup. */ /***** * 1) Command line paramter parsing would be done here. */ /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ /***** * 3) Setup real-time parameters. * In this example, we create a sporadic task that does not specify a * target partition (and thus is intended to run under global scheduling). * If this were to execute under a partitioned scheduler, it would be assigned * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); CALL( sporadic_global(EXEC_COST, PERIOD) ); /* To specify a partition, use sporadic_partitioned(). * Example: * * sporadic_partitioned(EXEC_COST, PERIOD, CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1. */ /***** * 4) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); /* The task is now executing as a real-time task if the call didn't fail. */ /***** * 5) Invoke real-time jobs. */ do { /* Wait until the next job is released. */ sleep_next_period(); /* Invoke job. */ do_exit = job(); } while (!do_exit); /***** * 6) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); /***** * 7) Clean up, maybe print results and stats, and exit. */ return 0; }
/* typically, main() does a couple of things: * 1) parse command line parameters, etc. * 2) Setup work environment. * 3) Setup real-time parameters. * 4) Transition to real-time mode. * 5) Invoke periodic or sporadic jobs. * 6) Transition to background mode. * 7) Clean up and exit. * * The following main() function provides the basic skeleton of a single-threaded * LITMUS^RT real-time task. In a real program, all the return values should be * checked for errors. */ int main(int argc, char** argv) { int do_exit, ret; struct rt_task param; wcet = atoi(argv[1]); // in ms period = atoi(argv[2]); // in ms dur = 1000 * atoi(argv[3]); // in seconds count = (dur / period) + 1; /* Setup task parameters */ memset(¶m, 0, sizeof(param)); param.exec_cost = wcet * NS_PER_MS; param.period = period * NS_PER_MS; param.relative_deadline = period * NS_PER_MS; /* What to do in the case of budget overruns? */ param.budget_policy = NO_ENFORCEMENT; /* The task class parameter is ignored by most plugins. */ param.cls = RT_CLASS_SOFT; param.cls = RT_CLASS_HARD; /* The priority parameter is only used by fixed-priority plugins. */ param.priority = LITMUS_LOWEST_PRIORITY; /* The task is in background mode upon startup. */ /***** * 1) Command line paramter parsing would be done here. */ /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ /***** * 3) Setup real-time parameters. * In this example, we create a sporadic task that does not specify a * target partition (and thus is intended to run under global scheduling). * If this were to execute under a partitioned scheduler, it would be assigned * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); /* To specify a partition, do * * param.cpu = CPU; * be_migrate_to(CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1 before calling * set_rt_task_param(). */ CALL( set_rt_task_param(gettid(), ¶m) ); /***** * 4) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); /* The task is now executing as a real-time task if the call didn't fail. */ ret = wait_for_ts_release(); if (ret != 0) printf("ERROR: wait_for_ts_release()"); /***** * 5) Invoke real-time jobs. */ do { /* Wait until the next job is released. */ sleep_next_period(); /* Invoke job. */ do_exit = job(); } while (!do_exit); /***** * 6) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); /***** * 7) Clean up, maybe print results and stats, and exit. */ return 0; }
/* typically, main() does a couple of things: * 1) parse command line parameters, etc. * 2) Setup work environment. * 3) Setup real-time parameters. * 4) Transition to real-time mode. * 5) Invoke periodic or sporadic jobs. * 6) Transition to background mode. * 7) Clean up and exit. * * The following main() function provides the basic skeleton of a single-threaded * LITMUS^RT real-time task. In a real program, all the return values should be * checked for errors. */ int main(int argc, char** argv) { int do_exit; int PERIOD, EXEC_COST, CPU; int sCounter; int counter; int pCounter; int ret; /* The task is in background mode upon startup. */ /***** * 1) Command line paramter parsing would be done here. */ if (argc !=5){ fprintf(stderr, "Usage: base_task EXEC_COST PERIOD COUNTER CPU \n COUNTER: print info every COUNTER times called \n"); exit(1); } EXEC_COST = atoi(argv[1]); PERIOD = atoi(argv[2]); sCounter = atoi(argv[3]); CPU = atoi(argv[4]); /***** * 2) Work environment (e.g., global data structures, file data, etc.) would * be setup here. */ counter = 0; pCounter = 0; /***** * 3) Setup real-time parameters. * In this example, we create a sporadic task that does not specify a * target partition (and thus is intended to run under global scheduling). * If this were to execute under a partitioned scheduler, it would be assigned * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); /* CALL( sporadic_global(EXEC_COST, PERIOD) ); */ /* To specify a partition, use sporadic_partitioned(). * Example: * * sporadic_partitioned(EXEC_COST, PERIOD, CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1. */ CALL( sporadic_partitioned(EXEC_COST, PERIOD, CPU) ); /***** * 4) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); /* The task is now executing as a real-time task if the call didn't fail. */ this_rt_id = gettid(); ret = wait_for_ts_release(); /***** * 5) Invoke real-time jobs. */ do { /* Wait until the next job is released. */ sleep_next_period(); /* Invoke job. */ do_exit = job(&counter, &pCounter, sCounter ); } while (!do_exit); /***** * 6) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); /***** * 7) Clean up, maybe print results and stats, and exit. */ return 0; }