hi everyone.
i want to write a milliSleep systemcall to my kernel but i'm not supposed to use nanosleep function internally with a clever parameter tweak
my millisleep function should be like this: int millisleep(int *amount). I've looked at the systemcall of nanosleep in timer.c but it takes two struct timespec parameters as an input. here is the systemcall code of nanosleep:
Code:
asmlinkage long sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp)
{
struct timespec t;
unsigned long expire;
if(copy_from_user(&t, rqtp, sizeof(struct timespec)))
return -EFAULT;
if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0 || t.tv_sec < 0)
return -EINVAL;
if (t.tv_sec == 0 && t.tv_nsec <= 2000000L &&
current->policy != SCHED_OTHER)
{
/*
* Short delay requests up to 2 ms will be handled with
* high precision by a busy wait for all real-time processes.
*
* Its important on SMP not to do this holding locks.
*/
udelay((t.tv_nsec + 999) / 1000);
return 0;
}
expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
current->state = TASK_INTERRUPTIBLE;
expire = schedule_timeout(expire);
if (expire) {
if (rmtp) {
jiffies_to_timespec(expire, &t);
if (copy_to_user(rmtp, &t, sizeof(struct timespec)))
return -EFAULT;
}
return -EINTR;
}
return 0;
}
and the struct timespec is defined in time.h like this:
Code:
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#endif /* _STRUCT_TIMESPEC */
i want to convert the nanosleep function into my millisleep function in the given format. I dont understand the meaning of the nanosleep function's two arguments. i want to define them as function will work for 1ns so i will run the function in a for loop with amount*1000000 times. how can i convert this code and what is the meaning af the arguments of nanosleep function?
( btw sorry for my english some mistakes can be in the text )