Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > The Linux Kernel
Reload this Page Linux (real-time) scheduling help
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

The Linux Kernel Compiling, theory, programming or other discussion about the linux kernel

Reply
 
Thread Tools Display Modes
Old 02-24-2008   #1 (permalink)
Just Joined!
 
Join Date: Feb 2008
Posts: 5
Linux (real-time) scheduling help

Hi, I need a confirmation that I got this right:

1. A thread gets created and put on a run queue, put there by class specific enqueue_task(), correct?

2. schedule() then picks this thread(assuming it is the best one), by calling the class specific pick_next() function and then switches it on the CPU, correct?

3. when the thread is on the CPU one of two things can happen assuming that it always have work to do, preemption or blocked, correct?

4. if the thread gets blocked the class specific dequeue_task() will be called and put it on a sleep queue, correct?

5. if the thread gets preempted the class specific function check_preempt_curr() will be called and the thread gets put back on its run queue, correct?

In the function check_preempt_curr_rt() I'm a little confused. Linux priorities ranges from 1-140 where 1 is the "highest" but the real-time priorities ranges from 1-99 where 99 is the highest? Is this correct? And p->prio in check_preempt_curr_rt() is the priority ranging from 1-140 with 1 highest right? and p->rt_prioirty is rt-prio ranging from 1-99, with 99 highest?

Code:
static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p)
{
    if (p->prio < rq->curr->prio) {
        resched_task(rq->curr);
    }
}
With this assumptions p is preempting rq->curr right? that is p gets ON the CPU and rq-curr gets OFF the CPU?
micke_b is offline   Reply With Quote
Old 02-25-2008   #2 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Hello,

The code logic looks decieving but I think that the check is designed to ensure that the realtime process is not preemted by another process...
Therefore, it checks to see if a process with a lower priority number has taken cpu time and if so it reschedules the real time process so that it can get back on the cpu...
brahan_7 is offline   Reply With Quote
Old 02-25-2008   #3 (permalink)
Just Joined!
 
Join Date: Feb 2008
Posts: 5
I'm not sure if Im buying that, I mean a real-time thread must also be able to preempt another real-time thread if is has higher prioirty ....
micke_b is offline   Reply With Quote
Old 02-26-2008   #4 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Lightbulb Ive got it!

Ok...I had to check my reference...

In real time processing 1 is the highest priority and 99 is the lowest priority, (this is according to the 3rd edition of Understanding the Linux kernel), you had that backwards...

So the subroutine is giving the next process 'p' cpu time if its priority is over the current one 'rq->curr->prio'.

However, processes have two different states...Active and Expired...if a process is active it is runnable until its time quantum is exhausted, (being runnable doesn't mean its running...it could be waiting but still active). Expired processes have to wait for active processes to expire before they are aloud anymore cpu time. (Basically there are two different tiers of scheduling) The catch is that realtime processes are always set to active...so they can only be preempted by other realtime processes of higher priority, which you already knew, but they cannot be preempted by conventional processes.

I think that answers your question

Check out Understanding the Linux Kernel:
O'Reilly Media | Understanding the Linux Kernel
brahan_7 is offline   Reply With Quote
Old 02-26-2008   #5 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Out of curiosity, what source file can that subroutine be found in?
brahan_7 is offline   Reply With Quote
Old 02-26-2008   #6 (permalink)
Just Joined!
 
Join Date: Feb 2008
Posts: 5
Its found in sched_rt.c in the [your kernel]/kernel folder I used kernel 2.6.23.12

Hmm, but when I make a real-time thread with prioirty 90 it will preempt a real-time thread with prioirty 80. This dosen't make any sense to me?

And in POSIX realtime priorities, the highest is the highets number, and Linux are suppose to support POSIX real-time priorities?

But I think there is a different between a tasks "prio" and "rt_prioriy" I think "prio" is the Linux own priority 1-140 with 1 beeing highest. And rt_prioirty is the POSIX version 1-99 with 99 highest. These maps 99-1(rt_priority) ro 1-99(prio) and 100-140 are non real-time prioirties.

Or am I just very confused?
micke_b is offline   Reply With Quote
Old 02-26-2008   #7 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Im assuming these threads are within the same kernel process. Give an example of how you create these threads...
brahan_7 is offline   Reply With Quote
Old 02-26-2008   #8 (permalink)
Just Joined!
 
Join Date: Feb 2008
Posts: 5
Arrow

Like this:

Code:
static int sched_sp_socket_priority;

int main(void){
  pthread_t ptid;
  struct sched_param sp;
  sched_sp_socket_priority = sched_get_priority_max(SCHED_FIFO);
  if((pthread_create(&ptid, NULL, socket_thread, NULL))) {
    perror("socket thread");
  }
  sp.sched_priority = sched_sp_socket_priority;
  if(pthread_setschedparam(ptid, SCHED_FIFO, &sp)) {
    perror("1. pthread_setschedparam failed!");
    return -1;
  }
}
This thread will preempt other threads created in the same process, and sp.sched_priority is 99.

Code:
sched_sp_socket_priority = sched_get_priority_max(SCHED_FIFO);
returns 99.
micke_b is offline   Reply With Quote
Old 02-27-2008   #9 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Lightbulb Sched_fifo

You are using 'SCHED_FIFI', which I'm sure you know means First In First Out, this is different from 'SCHED_OTHER' which would be the kernel default way of scheduling the threads, 1 being highest priority and 99 being lowest priority, to stay within 1 - 140...

if you were to say:
Code:
sched_get_priority_max(SCHED_OTHER);
you should get 0 and
if you said:
Code:
sched_get_priority_max(SCHED_OTHER);
you should get 0 also because the kernel handles the priorities...

So, using 'SHED_FIFO' or 'SHED_RR' you have min/max | 1/99 priorities for those threads within the process that you created...

You basically figured it out...

You need to make sure that 'check_preempt_curr_rt( )' is using the same kind of sched mechanism (FIFO, RR, OTHER) that you are using when you create the process.

Google SCHED_FIFO...you can find documentation for sched mechanisms.

Does that help at all?
brahan_7 is offline   Reply With Quote
Old 02-27-2008   #10 (permalink)
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
Out of curiosity again...what are you trying to create that uses real-time threading?
brahan_7 is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
 

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Unified Kernel 0.2.1 is released linooxlee The Coffee Lounge 2 02-23-2008 08:56 PM
Solving Boot Problems with Grub - 2nd Edition Nerderello Linux Tutorials, HOWTO's & Reference Material 4 02-06-2005 11:44 AM
Asking good questions (2) jasonlambert Linux Newbie 5 12-13-2004 09:22 PM
Securing Linux 101: Reasonable Steps flw Linux Tutorials, HOWTO's & Reference Material 0 07-13-2003 04:34 AM

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 04:25 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0