Beispiel #1
0
int sporadic_task_ns(lt_t e, lt_t p, lt_t phase,
		     int cpu, unsigned int priority,
		     task_class_t cls,
		     budget_policy_t budget_policy, int set_cpu_set)
{
	struct rt_task param;
	int ret;

	/* Zero out first --- this is helpful when we add plugin-specific
	 * parameters during development.
	 */
	memset(&param, 0, sizeof(param));

	param.exec_cost = e;
	param.period    = p;
	param.relative_deadline = p; /* implicit deadline */
	param.cpu       = cpu;
	param.cls       = cls;
	param.phase	= phase;
	param.budget_policy = budget_policy;
	param.priority  = priority;

	if (set_cpu_set) {
		ret = be_migrate_to(cpu);
		check("migrate to cpu");
	}
	return set_rt_task_param(gettid(), &param);
}
Beispiel #2
0
int generic_sporadic_task_ns(lt_t e, lt_t p, lt_t phase,
			int cpu, task_class_t cls,
			budget_policy_t budget_policy, int set_cpu_set, int dependent)
{
	struct rt_task param;
	int ret;

	/* Zero out first --- this is helpful when we add plugin-specific
	 * parameters during development.
	 */
	memset(&param, 0, sizeof(param));

	param.exec_cost = e;
	param.period    = p;
	param.subtask_period = p;
	param.cpu       = cpu;
	param.cls       = cls;
	param.phase	= phase;
	param.budget_policy = budget_policy;

	if (set_cpu_set) {
		ret = be_migrate_to(cpu);
		check("migrate to cpu");
	}
	return set_rt_task_param(gettid(), &param);
}
Beispiel #3
0
void* rt_thread(void *tcontext) {
	struct thread_context *ctx = (struct thread_context *) tcontext;
	struct rt_task param;

	/* set up litmus real-time task*/
	be_migrate_to_domain(ctx->cpu);
	init_rt_task_param(&param);
	param.priority = ctx->priority;
	param.cpu = ctx->cpu;
	param.exec_cost = ms2ns(3000);
	param.period = ms2ns(10000);
	param.relative_deadline = ms2ns(15000);
	param.budget_policy = NO_ENFORCEMENT;
	param.cls = RT_CLASS_HARD;
	param.enable_help = helping;
	param.non_preemption_after_migrate = non_preemption;

	init_rt_thread();
	if (set_rt_task_param(gettid(), &param) != 0)
		printf("set_rt_task_param error. \n ");
	task_mode(LITMUS_RT_TASK);


	lock_1 = litmus_open_lock(7, 1, "b", init_prio_per_cpu(4, 10, 10, 10, 10));
	
	do {
		lt_sleep(10);
		job(ctx);

		count_first++;
		if (count_first >= executions)
			exit_program = 1;
		
	} while (exit_program != 1);


	task_mode(BACKGROUND_TASK);
	return NULL;
}
Beispiel #4
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(&param);
  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(), &param) );  // 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;
}
Beispiel #5
0
/* A real-time thread is very similar to the main function of a single-threaded
 * real-time app. Notice, that init_rt_thread() is called to initialized per-thread
 * data structures of the LITMUS^RT user space libary.
 */
void* rt_thread(void *tcontext)
{
	int do_exit;
	struct thread_context *ctx = (struct thread_context *) tcontext;
	struct rt_task param;

	/* Set up task parameters */
	memset(&param, 0, sizeof(param));
	param.exec_cost = EXEC_COST * NS_PER_MS;
	param.period = PERIOD * NS_PER_MS;
	param.relative_deadline = RELATIVE_DEADLINE * 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;

	/* The priority parameter is only used by fixed-priority plugins. */
	param.priority = LITMUS_LOWEST_PRIORITY;

	/* Make presence visible. */
	printf("RT Thread %d active.\n", ctx->id);

	/*****
	 * 1) Initialize real-time settings.
	 */
	CALL( init_rt_thread() );

	/* 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(), &param) );

	/*****
	 * 2) 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. 
	 */



	/*****
	 * 3) Invoke real-time jobs.
	 */
	do {
		/* Wait until the next job is released. */
		sleep_next_period();
		/* Invoke job. */
		do_exit = job();		
	} while (!do_exit);


	
	/*****
	 * 4) Transition to background mode.
	 */
	CALL( task_mode(BACKGROUND_TASK) );


	return NULL;
}
Beispiel #6
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(&param, 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(), &param) );
    
    
    /*****
     * 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;
}
Beispiel #7
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(&param, 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(), &param) );


	/*****
	 * 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;
}
Beispiel #8
0
#include <sys/wait.h> /* for waitpid() */
#include <unistd.h>
#include <stdio.h>

#include "tests.h"
#include "litmus.h"


TESTCASE(set_rt_task_param_invalid_pointer, ALL,
	 "reject invalid rt_task pointers")
{
	SYSCALL_FAILS( EINVAL, set_rt_task_param(gettid(), NULL));

	SYSCALL_FAILS( EFAULT, set_rt_task_param(gettid(), (void*) 0x123 ));
}

TESTCASE(set_rt_task_param_invalid_params, ALL,
	 "reject invalid rt_task values")
{
	struct rt_task params;
	params.cpu        = 0;
	params.period     = 100;
	params.relative_deadline = params.period;
	params.phase      = 0;
	params.priority	  = LITMUS_LOWEST_PRIORITY;
	params.cls        = RT_CLASS_HARD;
	params.budget_policy = NO_ENFORCEMENT;

	/* over utilize */
	params.exec_cost  = 110;
	SYSCALL_FAILS( EINVAL, set_rt_task_param(gettid(), &params) );