Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <errno.h>
- #include <stdint.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <linux/kernel.h>
- #include <linux/types.h>
- #include <syscall.h>
- #include <math.h>
- #include <sched.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/mman.h>
- #include <sched.h>
- #include <linux/sched.h>
- #include <signal.h>
- #include <execinfo.h>
- #include <getopt.h>
- #include <sys/sysinfo.h>
- #define __NR_sched_setattr 314
- #define __NR_sched_getattr 315
- #define RTIME long long int
- #define rt_printk printf
- #define SCHED_DEADLINE 6
- struct sched_attr {
- __u32 size;
- __u32 sched_policy;
- __u64 sched_flags;
- /* SCHED_NORMAL, SCHED_BATCH */
- __s32 sched_nice;
- /* SCHED_FIFO, SCHED_RR */
- __u32 sched_priority;
- /* SCHED_DEADLINE (nsec) */
- __u64 sched_runtime;
- __u64 sched_deadline;
- __u64 sched_period;
- } sched_attr_t;
- int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags){
- return syscall(__NR_sched_setattr, pid, attr, flags);
- }
- int sched_getattr(pid_t pid,struct sched_attr *attr,unsigned int size, unsigned int flags){
- return syscall(__NR_sched_getattr, pid, attr, size, flags);
- }
- #define gettid() syscall(__NR_gettid) // for gettid
- static volatile int done;
- void *run_deadline(void *data){
- struct sched_attr attr;
- int x = 0, ret;
- unsigned int flags = 0;
- printf("deadline thread start %ldn", gettid());
- attr.size = sizeof(attr);
- attr.sched_flags = 0;
- attr.sched_nice = 0;
- attr.__sched_priority = 0;
- attr.sched_policy = SCHED_DEADLINE;
- attr.sched_period = 30 * 1000 * 1000;
- attr.sched_runtime = 10 * 1000 * 1000;
- attr.sched_deadline = 30 * 1000 * 1000;
- ret = sched_setattr(0, &attr, flags);
- if(ret < 0){
- done = 0;
- perror("sched_setattr");
- exit(-1);
- }
- while(!done){
- x++;
- }
- printf("x = %d n", x);
- return NULL;
- }
- int main(){
- pthread_t thread;
- printf("main thread [%ld] n", gettid());
- pthread_create(&thread, NULL, run_deadline, NULL);
- sleep(10);
- done = 1;
- pthread_join(thread, NULL);
- printf("main dies [%ld] n", gettid());
- return 0;
- }
- kay@IET:~/eclipse-workspace/dlsched/Debug$ sudo ./dlsched
- main thread [29485]
- deadline thread start 29486
- x = 920417116
- main dies [29485]
Add Comment
Please, Sign In to add comment