2005-03-22 22:26:50

by Arun Srinivas

[permalink] [raw]
Subject: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

Pls. help me. I went through the sched.c for kernel 2.6 and saw that it
supports
hyperthreading.I would be glad if someone could answer this question....(if
am not wrong a HT processor has 2 architectural states and one execution
unit...i.e., two pipeline streams)

1)when there are 2 processes a parent and child(created by fork()) do they
get scheduled @ the same time...ie., when the parent process is put into one
pipeline, do the child also gets scheduled the same time?

2) what abt in the case of threads(I read tht as opposed to kernel2.4,where
threads are treated as processes) ..kernel 2.6 treats threads as threads.
So, when two paired threads get into execution are they always scheduled at
the same time?

Also, it would be helpful if someone could suggest which part of sched.c
shud i look into to find out how threads are scheduled for a normal
processor and for a hyperthreaded processor

Pls. CC your replies to this email address [email protected]

Thanks
Arun

_________________________________________________________________
Don't know where to look for your life partner?
http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 Trust
BharatMatrimony.com


2005-03-22 23:17:59

by Nick Piggin

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

Arun Srinivas wrote:
> Pls. help me. I went through the sched.c for kernel 2.6 and saw that it
> supports
> hyperthreading.I would be glad if someone could answer this question....(if
> am not wrong a HT processor has 2 architectural states and one execution
> unit...i.e., two pipeline streams)
>
> 1)when there are 2 processes a parent and child(created by fork()) do they
> get scheduled @ the same time...ie., when the parent process is put into
> one
> pipeline, do the child also gets scheduled the same time?
>

No.

> 2) what abt in the case of threads(I read tht as opposed to kernel2.4,where
> threads are treated as processes) ..kernel 2.6 treats threads as threads.
> So, when two paired threads get into execution are they always scheduled at
> the same time?
>

No.

> Also, it would be helpful if someone could suggest which part of sched.c
> shud i look into to find out how threads are scheduled for a normal
> processor and for a hyperthreaded processor
>

It is pretty tricky. Basically processes on different CPUs are
scheduled completely independently of one another. The only time
when they may get moved from one CPU to another is with
load_balance, load_balance_newidle, active_load_balance,
try_to_wake_up, sched_exec, wake_up_new_task.

2005-03-23 06:08:10

by Arun Srinivas

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

If the SMT (apart from SMP) support is enabled in the .config file, does
the kernel recogonize the 2 logical processor as 2 logical or 2 physical
processors?

Also, as the hyperthreaded processor may schedule 2 threads in the 2 logical
cpu's, and it may not necessarily be form the same process i.e., the 2
thread it schedules may be from the same or from the different process.

So, is there any way I can tell the scheduler (assuming I make the scheduler
recogonize my 2 threads..i.e., it knows their pid) to schedule always my 2
threads @ the same time? How do I go abt it?

Pls. help.Thanks in Advance.

>From: Nick Piggin <[email protected]>
>To: Arun Srinivas <[email protected]>
>CC: [email protected]
>Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related
>questions?
>Date: Wed, 23 Mar 2005 10:16:20 +1100
>
>Arun Srinivas wrote:
>>Pls. help me. I went through the sched.c for kernel 2.6 and saw that it
>>supports
>>hyperthreading.I would be glad if someone could answer this
>>question....(if
>>am not wrong a HT processor has 2 architectural states and one execution
>>unit...i.e., two pipeline streams)
>>
>>1)when there are 2 processes a parent and child(created by fork()) do they
>>get scheduled @ the same time...ie., when the parent process is put into
>>one
>>pipeline, do the child also gets scheduled the same time?
>>
>
>No.
>
>>2) what abt in the case of threads(I read tht as opposed to
>>kernel2.4,where
>>threads are treated as processes) ..kernel 2.6 treats threads as threads.
>>So, when two paired threads get into execution are they always scheduled
>>at
>>the same time?
>>
>
>No.
>
>>Also, it would be helpful if someone could suggest which part of sched.c
>>shud i look into to find out how threads are scheduled for a normal
>>processor and for a hyperthreaded processor
>>
>
>It is pretty tricky. Basically processes on different CPUs are
>scheduled completely independently of one another. The only time
>when they may get moved from one CPU to another is with
>load_balance, load_balance_newidle, active_load_balance,
>try_to_wake_up, sched_exec, wake_up_new_task.
>

_________________________________________________________________
News, views and gossip. http://www.msn.co.in/Cinema/ Get it all at MSN
Cinema!

2005-03-23 07:08:40

by Jan Engelhardt

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

> It is pretty tricky. Basically processes on different CPUs are
> scheduled completely independently of one another. The only time
> when they may get moved from one CPU to another is with
> load_balance, load_balance_newidle, active_load_balance,
> try_to_wake_up, sched_exec, wake_up_new_task.

And of course, migrate_task() if I'm not mistaken. :)



Jan Engelhardt
--

2005-03-23 07:37:26

by Nick Piggin

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

Arun Srinivas wrote:
> If the SMT (apart from SMP) support is enabled in the .config file,
> does the kernel recogonize the 2 logical processor as 2 logical or 2
> physical processors?
>

You shouldn't be able to select SMT if SMP is not enabled.
If SMT and SMP is selected, then the scheduler will recognise
the 2 processors as logical ones.

> Also, as the hyperthreaded processor may schedule 2 threads in the 2
> logical cpu's, and it may not necessarily be form the same process i.e.,
> the 2 thread it schedules may be from the same or from the different
> process.
>

Yes.

> So, is there any way I can tell the scheduler (assuming I make the
> scheduler recogonize my 2 threads..i.e., it knows their pid) to schedule
> always my 2 threads @ the same time? How do I go abt it?
>

Use sched_setaffinity to force each thread onto the particular
CPU. Use sched_setscheduler to acquire a realtime scheduling
policy. Then use mutexes to synchronise your threads so they
run the desired code segment at the same time.

2005-03-23 09:47:54

by Arun Srinivas

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

few more trivial Q's (bear with me I'm a newbie to kernel world):

1) As I said I have a process that spawns 2 threads(thread A and B).I am
trying to measure the exact time @ which they are being scheduled.For this I
am using the rdtsc() (when threads A and B come) in enqueue_task()..where
they are being inserted into the priority array.
Is this a correct way of measuring?

2) also in task_struct.....is "tgid" the id of my process and each of
threads hav a unique pid??

3) I saw frm the kernel docs tht realtime tasks hav priority 0 to 99. So
using setscheduler means do I have to enforce a priority in one of these
ranges to make my threads as soft/hard realtime task.

thanks in advance for your patience.

>From: Nick Piggin <[email protected]>
>To: Arun Srinivas <[email protected]>
>CC: [email protected]
>Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related
>questions?
>Date: Wed, 23 Mar 2005 18:37:16 +1100
>
>Arun Srinivas wrote:
>>If the SMT (apart from SMP) support is enabled in the .config file, does
>>the kernel recogonize the 2 logical processor as 2 logical or 2 physical
>>processors?
>>
>
>You shouldn't be able to select SMT if SMP is not enabled.
>If SMT and SMP is selected, then the scheduler will recognise
>the 2 processors as logical ones.
>
>>Also, as the hyperthreaded processor may schedule 2 threads in the 2
>>logical cpu's, and it may not necessarily be form the same process i.e.,
>>the 2 thread it schedules may be from the same or from the different
>>process.
>>
>
>Yes.
>
>>So, is there any way I can tell the scheduler (assuming I make the
>>scheduler recogonize my 2 threads..i.e., it knows their pid) to schedule
>>always my 2 threads @ the same time? How do I go abt it?
>>
>
>Use sched_setaffinity to force each thread onto the particular
>CPU. Use sched_setscheduler to acquire a realtime scheduling
>policy. Then use mutexes to synchronise your threads so they
>run the desired code segment at the same time.
>

_________________________________________________________________
Screensavers unlimited! http://www.msn.co.in/Download/screensaver/ Download
now!

2005-03-24 00:17:17

by Nick Piggin

[permalink] [raw]
Subject: Re: help needed pls. scheduler(kernel 2.6) + hyperthreaded related questions?

Arun Srinivas wrote:
> few more trivial Q's (bear with me I'm a newbie to kernel world):
>
> 1) As I said I have a process that spawns 2 threads(thread A and B).I am
> trying to measure the exact time @ which they are being scheduled.For
> this I am using the rdtsc() (when threads A and B come) in
> enqueue_task()..where they are being inserted into the priority array.
> Is this a correct way of measuring?
>

Not exactly. They can be enqueued "onto" the runqueue without being
scheduled if there is another process running at the time.

You should look in schedule(). And use sched_clock instead of rdtsc.
I think you'll find schedule() already calls sched_clock, so you should
be able to do this with minimal overhead.

Note also, that schedule() may be called multiple times without
switching your task off the CPU - so keep that in mind if you are looking
for the time at which it is first scheduled on.

> 2) also in task_struct.....is "tgid" the id of my process and each of
> threads hav a unique pid??
>

Something like that.

> 3) I saw frm the kernel docs tht realtime tasks hav priority 0 to 99. So
> using setscheduler means do I have to enforce a priority in one of these
> ranges to make my threads as soft/hard realtime task.
>

Well, if you have nothing else running with a realtime scheduling policy,
then your process that is will always be scheduled first.

The priority only distinguishes between two realtime processes.

Oh, and Linux is not hard realtime. Meaning you don't have a deterministic
scheduling latency. But these days it is pretty good - probably not something
you'd have to worry about.

Nick

2005-03-29 03:28:44

by Arun Srinivas

[permalink] [raw]
Subject: sched_setscheduler() and usage issues ....please help


I am trying to set the SCHED_FIFO policy for my process.I am using
sched_setscheduler() function to do this.

I am following the correct syntax and running it as root process.I am using
the given syntax i.e.,
int sched_setscheduler(pid_t pid, int policy, const struct sched_param *p);
(SCHED_FIFO for the policy and priority in the range of 1 to 99 for p).

But the function returns with an value of -1. I am trying to call this
function from the user-space.

1) Is this usage correct?
2)How do I read the error code (i.e., text description of what kiind of
error occurred like for eg., ESRCH,EPERM,EINVAL).

Please help.

thanks
Arun

_________________________________________________________________
Don't know where to look for your life partner?
http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 Trust
BharatMatrimony.com

2005-03-29 04:40:38

by Steven Rostedt

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

On Tue, 2005-03-29 at 08:58 +0530, Arun Srinivas wrote:
> I am trying to set the SCHED_FIFO policy for my process.I am using
> sched_setscheduler() function to do this.

Attached is a little program that I use to set the priority of tasks.

-- Steve


Attachments:
setscheduler.c (1.78 kB)

2005-03-29 04:51:28

by Lee Revell

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

On Mon, 2005-03-28 at 23:40 -0500, Steven Rostedt wrote:
> On Tue, 2005-03-29 at 08:58 +0530, Arun Srinivas wrote:
> > I am trying to set the SCHED_FIFO policy for my process.I am using
> > sched_setscheduler() function to do this.
>
> Attached is a little program that I use to set the priority of tasks.

Why not just use chrt from schedtools?

Lee

2005-03-29 06:03:59

by Jan Engelhardt

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

>> > I am trying to set the SCHED_FIFO policy for my process.I am using
>> > sched_setscheduler() function to do this.
>>
>> Attached is a little program that I use to set the priority of tasks.
>
>Why not just use chrt from schedtools?

Not every distro has it yet, and I like to point out that a lot of users is
still using "older" distros, such as FC2, SUSE 9.1, and also olders with Linux
2.4 kernels.



Jan Engelhardt
--
No TOFU for me, please.

2005-03-29 11:36:25

by Steven Rostedt

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

On Tue, 2005-03-29 at 08:03 +0200, Jan Engelhardt wrote:
> >> > I am trying to set the SCHED_FIFO policy for my process.I am using
> >> > sched_setscheduler() function to do this.
> >>
> >> Attached is a little program that I use to set the priority of tasks.
> >
> >Why not just use chrt from schedtools?
>
> Not every distro has it yet, and I like to point out that a lot of users is
> still using "older" distros, such as FC2, SUSE 9.1, and also olders with Linux
> 2.4 kernels.

OK, I'm a little embarrassed. I never saw this tool. I use debian
unstable, but didn't have the package loaded. I did a apropos on
sched_setscheduler, and it didn't come up with any tools, so I just
wrote my own!

Thanks,

-- Steve


2005-03-29 11:40:44

by Jan Engelhardt

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

>OK, I'm a little embarrassed. I never saw this tool. I use debian

You don't need to be. Before I got to know of this tool, I also wrote my own.
Look for "schedutils".

>unstable, but didn't have the package loaded. I did a apropos on
>sched_setscheduler, and it didn't come up with any tools, so I just
>wrote my own!



Jan Engelhardt
--
No TOFU for me, please.

2005-03-29 11:45:07

by Arjan van de Ven

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

On Tue, 2005-03-29 at 08:03 +0200, Jan Engelhardt wrote:
> >> > I am trying to set the SCHED_FIFO policy for my process.I am using
> >> > sched_setscheduler() function to do this.
> >>
> >> Attached is a little program that I use to set the priority of tasks.
> >
> >Why not just use chrt from schedtools?
>
> Not every distro has it yet, and I like to point out that a lot of users is
> still using "older" distros, such as FC2, SUSE 9.1, and also olders with Linux
> 2.4 kernels

FC2 has this. Even FC1 had it, and I'd not be surprised if even RHL9 had
this. I'd be very susprised if SuSE 9.1 doesn't have it either.


2005-03-29 11:49:12

by Jan Engelhardt

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

>FC2 has this. Even FC1 had it, and I'd not be surprised if even RHL9 had
>this. I'd be very susprised if SuSE 9.1 doesn't have it either.

It was introduced with SUSE Linux 9.1. But, as usually, I usually do not care
for new packages when updating, and schedutils was not a dependency, so it
lost itself until I actively checked what it's about when the boot process
says
"Setting scheduling timeslices unused"





Jan Engelhardt
--
No TOFU for me, please.

2005-03-30 18:09:47

by Arun Srinivas

[permalink] [raw]
Subject: Re: sched_setscheduler() and usage issues ....please help

When I schedule my process with SCHED_FIFO policy (using
sched_setscheduler()) , is there any means to verify that it is indeed being
scheduled with the same priority?

thanks
arun
>From: Steven Rostedt <[email protected]>
>To: Arun Srinivas <[email protected]>
>Subject: Re: sched_setscheduler() and usage issues ....please help
>Date: Tue, 29 Mar 2005 06:31:43 -0500
>
>On Tue, 2005-03-29 at 13:25 +0530, Arun Srinivas wrote:
> > thanks.gcc says "could not find strutils.h". I am using kernel 2.6.x
>with
> > gcc 3.3.4. Where can I find the file?
>
>Oops! Sorry, I gave you a modified version of my actual program. I have
>my own usage wrapper, that I use in all my tools. I took it out, but
>forgot about my header. That is a custom header, just take it out and it
>will compile.
>
>OK, just to be clean, I've attached it here.
>
>-- Steve
>
><< setscheduler.c >>

_________________________________________________________________
Get the job you always wanted.
http://www.naukri.com/tieups/tieups.php?othersrcp=736 Its simple, post your
CV on Naukri.com