Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    sigset_t allsigs;
    int cur_val = 0;
	int s32CPUNo = 0;
	int s32CHDNo = 0;
	int s32i = 0;
	int s32pid = 0;

	if(argc != 3)
	{
		printf("Error!\n");
		exit(EXIT_FAILURE);
	}

	s32CPUNo = atoi(argv[1]);
	s32CHDNo = atoi(argv[2]) - 1;
	if(s32CPUNo < 0 || s32CPUNo > MAX_CORE_NO)
	{
		printf("OUT of Range\n");
		exit(EXIT_FAILURE);
	}

	printf("CPU bind: %d\n", s32CPUNo);
	set_cpu(s32CPUNo);
	printf("Set Sched:RR\n");
	set_sched();

	for(s32i = 0; s32i < s32CHDNo; s32i++)
	{
		s32pid = fork();
		if(0 == s32pid)
		{
			/* Child */
			break;
		}	
		else
		{
			/* Parent */
		}
	}
	

	for(s32i = 0; s32i < IRT_NUM; s32i++)
	{
	}
    
    exit(EXIT_SUCCESS);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    struct sigaction sa;
    sigset_t allsigs;
    struct itimerspec timerspec;
    struct timespec now;
    timer_t timer;
    struct sigevent timer_event;

	if(argc != 5)
	{
		fprintf(stderr, "Argu ERROR! ./calib_stage1 period count priority taskId\n");
		exit(EXIT_FAILURE);
	}
/*  We do not need a Wcet this time */
/*	wcet =		atoi(argv[1]);      */
	period =	atoi(argv[1]);
	count =		atoi(argv[2]);
	priority =  atoi(argv[3]);
	gu16RefID = atoi(argv[4]);


    printf("Task[%d] period[%d] count[%d] priority[%d]\n",
			gu16RefID, period, count, priority);
 
	sprintf(gacFileName, "Task%04d.trace", gu16RefID);
	/* Set SCHED_FIFO */
	set_sched();

	/* INIT Tracing */
	init_tracing();
	gs32PID = getpid();

	/* Bind a sighandler, using SIGRTMIN */
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO;
    sa.sa_sigaction = work;

    if (sigaction(SIGRTMIN, &sa, NULL) < 0) {
        perror("sigaction error");
        exit(EXIT_FAILURE);
    }

	/* Bind another sighander, using SIGINT */
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO;
    sa.sa_sigaction = exit_dump;

    if (sigaction(SIGINT, &sa, NULL) < 0) {
        perror("sigaction error");
        exit(EXIT_FAILURE);
    }
	

	/* We don't need an external trigger */
	/* raise(SIGSTOP); */

    /* the timer */
    timerspec.it_interval.tv_sec = period / 1000;
	/* Correct the Timer Interval Error Regardless of rdtsc*/
    timerspec.it_interval.tv_nsec = (period % 1000) * 1000000;

    /* the start time */
    /* if(clock_gettime(CLOCK_MONOTONIC, &now) < 0) { */
    if(clock_gettime(CLOCK_REALTIME, &now) < 0) {
        perror("clock_gettime");
        exit(EXIT_FAILURE);
    }

    // Start one second from now.
	/* add_record_task(TASK_EVENT_SET_TIMER, gu16RefID, gs32PID, 0); */
    timerspec.it_value.tv_sec = now.tv_sec + 1;
	/* Correct the Timer Start Error Regardless of rdtsc*/
    timerspec.it_value.tv_nsec = now.tv_nsec;

    timer_event.sigev_notify = SIGEV_SIGNAL;
    timer_event.sigev_signo = SIGRTMIN;
    timer_event.sigev_value.sival_ptr = (void *)&timer;

    if (timer_create(CLOCK_REALTIME, &timer_event, &timer) < 0) {
        perror("timer_create");
        exit(EXIT_FAILURE);
    }

    if (timer_settime(timer, TIMER_ABSTIME, &timerspec, NULL) < 0) {
        perror("timer_settime");
        exit(EXIT_FAILURE);
    }

    sigemptyset(&allsigs);



    while(1) {
        sigsuspend(&allsigs);
    }
    
    exit(EXIT_SUCCESS);
}
Exemplo n.º 3
0
static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
{
	struct sched_param sp = { .sched_priority = ctl->priority };
	int policy = ctl->policy;

# ifdef SCHED_RESET_ON_FORK
	if (ctl->reset_on_fork)
		policy |= SCHED_RESET_ON_FORK;
# endif
	return sched_setscheduler(pid, policy, &sp);
}

#else /* !HAVE_SCHED_SETATTR */
static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
{
	/* use main() to check if the setting makes sense */
	struct sched_attr sa = {
		.size		= sizeof(struct sched_attr),
		.sched_policy	= ctl->policy,
		.sched_priority	= ctl->priority,
		.sched_runtime  = ctl->runtime,
		.sched_period   = ctl->period,
		.sched_deadline = ctl->deadline
	};
# ifdef SCHED_RESET_ON_FORK
	if (ctl->reset_on_fork)
		sa.sched_flags |= SCHED_RESET_ON_FORK;
# endif
	return sched_setattr(pid, &sa, 0);
}
#endif /* HAVE_SCHED_SETATTR */

static void set_sched(struct chrt_ctl *ctl)
{
	if (ctl->all_tasks) {
		pid_t tid;
		struct proc_tasks *ts = proc_open_tasks(ctl->pid);

		if (!ts)
			err(EXIT_FAILURE, _("cannot obtain the list of tasks"));

		while (!proc_next_tid(ts, &tid))
			if (set_sched_one(ctl, tid) == -1)
				err(EXIT_FAILURE, _("failed to set tid %d's policy"), tid);

		proc_close_tasks(ts);

	} else if (set_sched_one(ctl, ctl->pid) == -1)
		err(EXIT_FAILURE, _("failed to set pid %d's policy"), ctl->pid);

	ctl->altered = 1;
}

int main(int argc, char **argv)
{
	struct chrt_ctl _ctl = { .pid = -1 }, *ctl = &_ctl;
	int c;

	static const struct option longopts[] = {
		{ "all-tasks",  no_argument, NULL, 'a' },
		{ "batch",	no_argument, NULL, 'b' },
		{ "deadline",   no_argument, NULL, 'd' },
		{ "fifo",	no_argument, NULL, 'f' },
		{ "idle",	no_argument, NULL, 'i' },
		{ "pid",	no_argument, NULL, 'p' },
		{ "help",	no_argument, NULL, 'h' },
		{ "max",        no_argument, NULL, 'm' },
		{ "other",	no_argument, NULL, 'o' },
		{ "rr",		no_argument, NULL, 'r' },
		{ "sched-runtime",  required_argument, NULL, 'T' },
		{ "sched-period",   required_argument, NULL, 'P' },
		{ "sched-deadline", required_argument, NULL, 'D' },
		{ "reset-on-fork",  no_argument,       NULL, 'R' },
		{ "verbose",	no_argument, NULL, 'v' },
		{ "version",	no_argument, NULL, 'V' },
		{ NULL,		no_argument, NULL, 0 }
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while((c = getopt_long(argc, argv, "+abdDfiphmoPTrRvV", longopts, NULL)) != -1)
	{
		int ret = EXIT_FAILURE;

		switch (c) {
		case 'a':
			ctl->all_tasks = 1;
			break;
		case 'b':
#ifdef SCHED_BATCH
			ctl->policy = SCHED_BATCH;
#endif
			break;

		case 'd':
#ifdef SCHED_DEADLINE
			ctl->policy = SCHED_DEADLINE;
#endif
			break;
		case 'f':
			ctl->policy = SCHED_FIFO;
			break;
		case 'R':
			ctl->reset_on_fork = 1;
			break;
		case 'i':
#ifdef SCHED_IDLE
			ctl->policy = SCHED_IDLE;
#endif
			break;
		case 'm':
			show_min_max();
			return EXIT_SUCCESS;
		case 'o':
			ctl->policy = SCHED_OTHER;
			break;
		case 'p':
			errno = 0;
			ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
			break;
		case 'r':
			ctl->policy = SCHED_RR;
			break;
		case 'v':
			ctl->verbose = 1;
			break;
		case 'T':
			ctl->runtime = strtou64_or_err(optarg, _("invalid runtime argument"));
			break;
		case 'P':
			ctl->period = strtou64_or_err(optarg, _("invalid period argument"));
			break;
		case 'D':
			ctl->deadline = strtou64_or_err(optarg, _("invalid deadline argument"));
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		case 'h':
			ret = EXIT_SUCCESS;
			/* fallthrough */
		default:
			show_usage(ret);
		}
	}

	if (((ctl->pid > -1) && argc - optind < 1) ||
	    ((ctl->pid == -1) && argc - optind < 2))
		show_usage(EXIT_FAILURE);

	if ((ctl->pid > -1) && (ctl->verbose || argc - optind == 1)) {
		show_sched_info(ctl);
		if (argc - optind == 1)
			return EXIT_SUCCESS;
	}

	errno = 0;
	ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));

#ifdef SCHED_RESET_ON_FORK
	if (ctl->reset_on_fork && ctl->policy != SCHED_FIFO && ctl->policy != SCHED_RR)
		errx(EXIT_FAILURE, _("--reset-on-fork option is supported for "
				     "SCHED_FIFO and SCHED_RR policies only"));
#endif
#ifdef SCHED_DEADLINE
	if ((ctl->runtime || ctl->deadline || ctl->period) && ctl->policy != SCHED_DEADLINE)
		errx(EXIT_FAILURE, _("--sched-{runtime,deadline,period} options "
				     "are supported for SCHED_DEADLINE only"));
	if (ctl->policy == SCHED_DEADLINE) {
		/* The basic rule is runtime <= deadline <= period, so we can
		 * make deadline and runtime optional on command line. Note we
		 * don't check any values or set any defaults, it's kernel
		 * responsibility.
		 */
		if (ctl->deadline == 0)
			ctl->deadline = ctl->period;
		if (ctl->runtime == 0)
			ctl->runtime = ctl->deadline;
	}
#else
	if (ctl->runtime || ctl->deadline || ctl->period)
		errx(EXIT_FAILURE, _("SCHED_DEADLINE is unsupported"));
#endif
	if (ctl->pid == -1)
		ctl->pid = 0;

	set_sched(ctl);

	if (ctl->verbose)
		show_sched_info(ctl);

	if (!ctl->pid) {
		argv += optind + 1;
		execvp(argv[0], argv);
		err(EXIT_FAILURE, _("failed to execute %s"), argv[0]);
	}

	return EXIT_SUCCESS;
}