public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Arun Srinivas <getarunsri@hotmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: scheduler/SCHED_FIFO behaviour
Date: Mon, 02 May 2005 12:33:17 -0400	[thread overview]
Message-ID: <1115051597.5081.19.camel@localhost.localdomain> (raw)
In-Reply-To: <BAY10-F2709F2A16EEE74732F797FD9270@phx.gbl>

On Mon, 2005-05-02 at 10:57 +0530, Arun Srinivas wrote:
> The 2 processes which I  am measuring  are parent and child processes.I want 
> both of'em to be scheduled at the same time.My code simply does the 
> following:
> 
> 1) From main(i.e., parent) create a shared memory seg. using shmget() and 
> shmat(). This is for communication between parent and child. I am trying to 
> use this as a locking mechanism to make them tightly coupled so that one 
> does not race before the other.
> 2) create child by fork() and call shmat() to attach this segment to child 
> too
> 3) In parent and child call ioctl() to pass their PID's from user space to 
> kernel space...so that I can measure when the particular PID's are scheduled 
> in the scheduler
> 
> I suppose shmget() dosent use a system call.So still confused about the 
> occasional resechedule behavior.

Uhh, yes it does:

$ vi shmget.c

i
#include <sys/ipc.h>
#include <sys/shm.h>

int main()
{
        shmget(123,123,0);
        return 0;
}
:wq

$ gcc -o shmget shmget.c
$ strace ./shmget
[snip]
  shmget(123, 123, 0)                     = -1 ENOENT (No such file or directory)
[snip]
---

So it is a system call.  

Now, I still don't know when you are using your locking (which is also a
system call) to run your code.  A child is usually added to the same run
queue as the parent.  So this means that it will be scheduled on the
same CPU as the parent. But if the other CPU scheduler notices that the
scheduling of processes on the CPUs are unbalanced, then it will pull
tasks from one CPU to the other. But once the tasks are running as
SCHED_FIFO on different CPUs, then they shouldn't be preempted.

BUT!!!

looking at the system call code for shmget:

asmlinkage long sys_shmget (key_t key, size_t size, int shmflg)
{
	struct shmid_kernel *shp;
	int err, id = 0;

	down(&shm_ids.sem);  ==========>>>>> Here we can schedule
	if (key == IPC_PRIVATE) {
		err = newseg(key, shmflg, size);
	} else if ((id = ipc_findkey(&shm_ids, key)) == -1) {
		if (!(shmflg & IPC_CREAT))
			err = -ENOENT;
		else
			err = newseg(key, shmflg, size);
	} else if ((shmflg & IPC_CREAT) && (shmflg & IPC_EXCL)) {
		err = -EEXIST;
	} else {
		shp = shm_lock(id);
		if(shp==NULL)
			BUG();
		if (shp->shm_segsz < size)
			err = -EINVAL;
		else if (ipcperms(&shp->shm_perm, shmflg))
			err = -EACCES;
		else {
			int shmid = shm_buildid(id, shp->shm_perm.seq);
			err = security_shm_associate(shp, shmflg);
			if (!err)
				err = shmid;
		}
		shm_unlock(shp);
	}
	up(&shm_ids.sem);

	return err;
}


So, if both the parent and child are going for the same shared memory,
you can cause one to schedule.

-- Steve



  parent reply	other threads:[~2005-05-02 16:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-07  1:41 scheduler/SCHED_FIFO behaviour Arun Srinivas
2005-04-07  2:27 ` Steven Rostedt
2005-05-01  2:06   ` Arun Srinivas
2005-05-01 15:51     ` Steven Rostedt
2005-05-02  5:27       ` Arun Srinivas
2005-05-02 10:37         ` Florian Schmidt
2005-05-02 16:33         ` Steven Rostedt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-04-03 23:08 sched /HT processor Steven Rostedt
2005-04-04 23:06 ` scheduler/SCHED_FIFO behaviour Arun Srinivas
2005-04-04 23:17   ` Steven Rostedt
2005-04-05  2:16     ` Arun Srinivas
2005-04-05  3:33       ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1115051597.5081.19.camel@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --cc=getarunsri@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox