mk_
mk_

Reputation: 417

Mechanism for yielding cpu

I have a module which creates a kthread. I want this kthread to record some statistics, then yield the cpu. It will record statistics when it runs again. What is the correct way to do this? Is

set_tsk_need_reched(task); 
schedule();

the right way to do this? (It seems not to do what I expect)

Upvotes: 4

Views: 1981

Answers (1)

ZarathustrA
ZarathustrA

Reputation: 3630

If I correly remember Linux kernel have a yield() function that can be used to voluntarily pass processor control to some another thread in the system (kernel will decide itself what thread will be running next). Some notes:

  • You need to call yield() from the context of your thread.
  • You needn't to invoke scheduler explicitly after that. yield() code will force rescheduling by itself.

Upvotes: 1

Related Questions