linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: george anzinger <george@mvista.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Jim Houston <jim.houston@ccur.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	LKML <linux-kernel@vger.kernel.org>,
	anton@samba.org, "David S. Miller" <davem@redhat.com>,
	ak@muc.de, davidm@hpl.hp.com, schwidefsky@de.ibm.com,
	ralf@gnu.org, willy@debian.org
Subject: Re: [PATCH] compatibility syscall layer (lets try again)
Date: Fri, 06 Dec 2002 01:17:09 -0800	[thread overview]
Message-ID: <3DF06B15.1F6ECD5D@mvista.com> (raw)
In-Reply-To: Pine.LNX.4.44.0212050846100.27298-100000@home.transmeta.com

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

Linus Torvalds wrote:
> 
> On Thu, 5 Dec 2002, george anzinger wrote:
> >
> > I think this covers all the bases.  It builds boots and
> > runs.  I haven't tested nano_sleep to see if it does the
> > right thing yet...
> 
> Well, it definitely doesn't, since at least this test is the wrong way
> around (as well as being against the coding style whitespace rules ;-p):
> 
> +       if ( ! current_thread_info()->restart_block.fun){
> +               return current_thread_info()->restart_block.fun(&parm);
> 
> Also, I would suggest against having a NULL pointer, and instead just
> initializing it with a function that sets it to an error return (don't use
> ENOSYS, since the system call _does_ exist, and ENOSYS is what old kernels
> would return if you do it by hand by mistake. I'd suggest -EINTR, since
> that will "DoTheRightThing(tm)" if we somehow get confused).
> 
>                 Linus
Ok, all the changes are in this version.  It build, runs AND
passes my clock_nanosleep test (when combined with the posix
timers patch).  I "annoy" the sleep with SIGSTOP and friends
and test the times against expected.

-- 
George Anzinger   george@mvista.com
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml

[-- Attachment #2: reg-fix-2.5.50-bk5-1.0.patch --]
[-- Type: text/plain, Size: 7221 bytes --]

diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/arch/i386/kernel/entry.S linux/arch/i386/kernel/entry.S
--- linux-2.5.50-bk5-kb/arch/i386/kernel/entry.S	Thu Dec  5 12:28:15 2002
+++ linux/arch/i386/kernel/entry.S	Thu Dec  5 12:28:52 2002
@@ -769,6 +769,7 @@
 	.long sys_epoll_wait
  	.long sys_remap_file_pages
  	.long sys_set_tid_address
+	.long sys_restart_syscall
 
 
 	.rept NR_syscalls-(.-sys_call_table)/4
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/arch/i386/kernel/signal.c linux/arch/i386/kernel/signal.c
--- linux-2.5.50-bk5-kb/arch/i386/kernel/signal.c	Thu Oct  3 10:41:57 2002
+++ linux/arch/i386/kernel/signal.c	Thu Dec  5 12:28:52 2002
@@ -506,6 +506,9 @@
 	if (regs->orig_eax >= 0) {
 		/* If so, check system call restarting.. */
 		switch (regs->eax) {
+		        case -ERESTART_RESTARTBLOCK:
+				current_thread_info()->restart_block.fun = 
+					do_no_restart_syscall;
 			case -ERESTARTNOHAND:
 				regs->eax = -EINTR;
 				break;
@@ -589,6 +592,10 @@
 		    regs->eax == -ERESTARTSYS ||
 		    regs->eax == -ERESTARTNOINTR) {
 			regs->eax = regs->orig_eax;
+			regs->eip -= 2;
+		}
+		if (regs->eax == -ERESTART_RESTARTBLOCK){
+			regs->eax = __NR_restart_syscall;
 			regs->eip -= 2;
 		}
 	}
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/include/asm-i386/thread_info.h linux/include/asm-i386/thread_info.h
--- linux-2.5.50-bk5-kb/include/asm-i386/thread_info.h	Mon Sep  9 10:35:03 2002
+++ linux/include/asm-i386/thread_info.h	Thu Dec  5 12:28:53 2002
@@ -11,6 +11,7 @@
 
 #ifndef __ASSEMBLY__
 #include <asm/processor.h>
+#include <linux/linkage.h>
 #endif
 
 /*
@@ -20,6 +21,12 @@
  * - if the contents of this structure are changed, the assembly constants must also be changed
  */
 #ifndef __ASSEMBLY__
+struct restart_block {
+	long (*fun)(void *);
+	long arg0;
+	long arg1;
+};
+
 struct thread_info {
 	struct task_struct	*task;		/* main task structure */
 	struct exec_domain	*exec_domain;	/* execution domain */
@@ -31,6 +38,7 @@
 					 	   0-0xBFFFFFFF for user-thead
 						   0-0xFFFFFFFF for kernel-thread
 						*/
+	struct restart_block    restart_block;
 
 	__u8			supervisor_stack[0];
 };
@@ -44,6 +52,7 @@
 #define TI_CPU		0x0000000C
 #define TI_PRE_COUNT	0x00000010
 #define TI_ADDR_LIMIT	0x00000014
+#define TI_RESTART_BLOCK 0x0000018
 
 #endif
 
@@ -55,6 +64,12 @@
  * preempt_count needs to be 1 initially, until the scheduler is functional.
  */
 #ifndef __ASSEMBLY__
+/*
+ * We need this to do the initialization, but we don't want to clutter up
+ * things with the signal.h which is where it should be...
+ */
+extern asmlinkage long do_no_restart_syscall( void *parm);
+
 #define INIT_THREAD_INFO(tsk)			\
 {						\
 	.task		= &tsk,			\
@@ -63,6 +78,9 @@
 	.cpu		= 0,			\
 	.preempt_count	= 1,			\
 	.addr_limit	= KERNEL_DS,		\
+	.restart_block = {                      \
+		.fun = do_no_restart_syscall,   \
+	},		                        \
 }
 
 #define init_thread_info	(init_thread_union.thread_info)
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/include/asm-i386/unistd.h linux/include/asm-i386/unistd.h
--- linux-2.5.50-bk5-kb/include/asm-i386/unistd.h	Wed Nov 27 15:49:22 2002
+++ linux/include/asm-i386/unistd.h	Thu Dec  5 12:28:53 2002
@@ -263,7 +263,7 @@
 #define __NR_sys_epoll_wait	256
 #define __NR_remap_file_pages	257
 #define __NR_set_tid_address	258
-
+#define __NR_restart_syscall    259
 
 /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
 
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/include/linux/errno.h linux/include/linux/errno.h
--- linux-2.5.50-bk5-kb/include/linux/errno.h	Mon Sep  9 10:35:15 2002
+++ linux/include/linux/errno.h	Thu Dec  5 12:28:54 2002
@@ -10,6 +10,7 @@
 #define ERESTARTNOINTR	513
 #define ERESTARTNOHAND	514	/* restart if no handler.. */
 #define ENOIOCTLCMD	515	/* No ioctl command */
+#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
 
 /* Defined for the NFSv3 protocol */
 #define EBADHANDLE	521	/* Illegal NFS file handle */
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/include/linux/signal.h linux/include/linux/signal.h
--- linux-2.5.50-bk5-kb/include/linux/signal.h	Mon Sep  9 10:35:04 2002
+++ linux/include/linux/signal.h	Thu Dec  5 12:28:54 2002
@@ -219,6 +219,7 @@
 }
 
 extern long do_sigpending(void *, unsigned long);
+extern asmlinkage long do_no_restart_syscall( void *parm);
 
 #ifndef HAVE_ARCH_GET_SIGNAL_TO_DELIVER
 struct pt_regs;
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/kernel/signal.c linux/kernel/signal.c
--- linux-2.5.50-bk5-kb/kernel/signal.c	Thu Dec  5 11:48:53 2002
+++ linux/kernel/signal.c	Thu Dec  5 12:28:54 2002
@@ -1351,6 +1351,19 @@
  * System call entry points.
  */
 
+asmlinkage long
+sys_restart_syscall( void *parm)
+{
+	return current_thread_info()->restart_block.fun(&parm);
+}
+
+asmlinkage long
+do_no_restart_syscall( void *parm)
+{
+	return -EINTR;
+}
+
+
 /*
  * We don't need to get the kernel lock - this is all local to this
  * particular thread.. (and that's good, because this is _heavily_
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.50-bk5-kb/kernel/timer.c linux/kernel/timer.c
--- linux-2.5.50-bk5-kb/kernel/timer.c	Thu Dec  5 11:48:53 2002
+++ linux/kernel/timer.c	Thu Dec  5 12:48:54 2002
@@ -1020,21 +1020,50 @@
 	return current->pid;
 }
 
+struct nano_sleep_call {
+	struct timespec *rqtp; 
+	struct timespec *rmtp;
+};
+
+asmlinkage long sys_nanosleep_restart( struct nano_sleep_call * parms);
+
+
 long do_nanosleep(struct timespec *t)
 {
 	unsigned long expire;
+	struct  restart_block *restart_block = 
+		&current_thread_info()->restart_block;
 
-	if ((t->tv_nsec >= 1000000000L) || (t->tv_nsec < 0) || (t->tv_sec < 0))
-		return -EINVAL;
+	if( restart_block->fun == (int (*)(void *))sys_nanosleep_restart){
+		/*
+		 * Interrupted by a non-delivered signal, pick up remaining
+		 * time and continue.
+		 */
+		restart_block->fun = do_no_restart_syscall;
+		if(!restart_block->arg0)
+			return  -EINTR;
+
+		expire = restart_block->arg0 - jiffies;
+		if(expire <= 0)
+			return 0;
+	}else{
+		if ((t->tv_nsec >= 1000000000L) || 
+		    (t->tv_nsec < 0) || 
+		    (t->tv_sec < 0))
+			return -EINVAL;
 
-	expire = timespec_to_jiffies(t) + (t->tv_sec || t->tv_nsec);
+		expire = timespec_to_jiffies(t) + (t->tv_sec || t->tv_nsec);
+	}
 
 	current->state = TASK_INTERRUPTIBLE;
 	expire = schedule_timeout(expire);
 
 	if (expire) {
 		jiffies_to_timespec(expire, t);
-		return -EINTR;
+		restart_block = &current_thread_info()->restart_block;
+		restart_block->fun = (int (*)(void *))sys_nanosleep_restart;
+		restart_block->arg0 = jiffies + expire;
+		return -ERESTART_RESTARTBLOCK;
 	}
 	return 0;
 }
@@ -1048,11 +1077,16 @@
 		return -EFAULT;
 
 	ret = do_nanosleep(&t);
-	if (rmtp && (ret == -EINTR)) {
+	if (rmtp && (ret == -ERESTART_RESTARTBLOCK)) {
 		if (copy_to_user(rmtp, &t, sizeof(t)))
 			return -EFAULT;
 	}
 	return ret;
+}
+
+asmlinkage long sys_nanosleep_restart( struct nano_sleep_call * parms)
+{
+	return sys_nanosleep(parms->rqtp, parms->rmtp);
 }
 
 /*

  reply	other threads:[~2002-12-06  9:11 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-04  7:02 [PATCH] compatibility syscall layer (lets try again) Stephen Rothwell
2002-12-04  7:07 ` [PATCH] compatibility syscall layer - PPC64 Stephen Rothwell
2002-12-06 23:03   ` Anton Blanchard
2002-12-04  7:16 ` [PATCH] compatibility syscall layer - SPARC64 Stephen Rothwell
2002-12-04  7:18 ` [PATCH] compatibility syscall layer - X86_64 Stephen Rothwell
2002-12-04 11:29   ` Andi Kleen
2002-12-04  7:26 ` [PATCH] compatibility syscall layer - IA64 Stephen Rothwell
2002-12-04  7:37   ` David Mosberger
2002-12-04  7:28 ` [PATCH] compatibility syscall layer (lets try again) Stephen Rothwell
2002-12-04  7:29 ` [PATCH] compatibility syscall layer - PARISC Stephen Rothwell
2002-12-04  7:30 ` [PATCH] compatibility syscall layer (lets try again) Stephen Rothwell
2002-12-04  7:33 ` Stephen Rothwell
2002-12-04 11:57 ` Pavel Machek
2002-12-04 16:54 ` Linus Torvalds
2002-12-04 16:54   ` David S. Miller
2002-12-04 17:05     ` Linus Torvalds
2002-12-04 19:56 ` george anzinger
2002-12-04 20:07   ` Linus Torvalds
2002-12-04 20:56     ` Daniel Jacobowitz
2002-12-04 22:09       ` David S. Miller
2002-12-04 22:31         ` george anzinger
2002-12-04 22:39           ` David S. Miller
2002-12-04 22:42           ` Linus Torvalds
2002-12-04 23:42     ` Jim Houston
2002-12-05  0:18       ` Linus Torvalds
2002-12-05  2:01         ` george anzinger
2002-12-05  2:51           ` Linus Torvalds
2002-12-05  3:10             ` Andi Kleen
2002-12-05  3:46             ` george anzinger
2002-12-05  4:11               ` Linus Torvalds
2002-12-05  7:10                 ` george anzinger
2002-12-05  9:48                 ` george anzinger
2002-12-05 15:24                   ` Jim Houston
2002-12-05 16:35                     ` george anzinger
2002-12-06  0:03                       ` Richard Henderson
2002-12-05 17:03                   ` Linus Torvalds
2002-12-06  9:17                     ` george anzinger [this message]
2002-12-06 17:57                       ` Linus Torvalds
2002-12-06 19:20                         ` Linus Torvalds
2002-12-06 20:09                           ` [PATCH] compatibility syscall layer (let's " Jim Houston
2002-12-06 20:33                             ` george anzinger
2002-12-06 20:18                           ` [PATCH] compatibility syscall layer (lets " george anzinger
2002-12-06 21:12                             ` Linus Torvalds
2002-12-06 21:56                               ` Jim Houston
2002-12-06 22:58                                 ` Linus Torvalds
2002-12-07  2:25                                   ` george anzinger
2002-12-06 23:08                                 ` george anzinger
2002-12-08 20:41                           ` David S. Miller
2002-12-09  6:18                             ` Stephen Rothwell
2002-12-09 15:41                         ` Daniel Jacobowitz
2002-12-09 16:48                           ` Linus Torvalds
2002-12-09 17:27                             ` David Mosberger
2002-12-09 20:22                               ` David S. Miller
2002-12-09 17:49                             ` Jim Houston
2002-12-09 17:57                               ` Linus Torvalds
2002-12-09 23:30                             ` Paul Mackerras
2002-12-10 23:07                           ` george anzinger
2002-12-11  7:10                             ` Daniel Jacobowitz
2002-12-11  8:11                               ` george anzinger
2002-12-11  8:26                                 ` Daniel Jacobowitz
2002-12-10 11:08             ` Jamie Lokier
2002-12-05  2:27         ` Jim Houston
  -- strict thread matches above, loose matches on Subject: below --
2002-12-09 16:58 Mikael Starvik
2002-12-09 17:35 ` Linus Torvalds
2002-12-09 18:46   ` David Mosberger
2002-12-10  0:13   ` Paul Mackerras
2002-12-10 23:11     ` george anzinger
2002-12-09 17:16 Martin Schwidefsky
2002-12-09 17:33 ` Linus Torvalds
2002-12-09 20:18 ` David S. Miller
2002-12-09 17:56 Martin Schwidefsky
2002-12-09 18:20 ` Linus Torvalds
2002-12-10 14:40 ` Keith Owens
2002-12-09 18:41 Martin Schwidefsky
2002-12-09 18:52 ` Linus Torvalds
2002-12-10  8:20   ` george anzinger
2002-12-10  8:42 Martin Schwidefsky
2002-12-10 17:17 Martin Schwidefsky

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=3DF06B15.1F6ECD5D@mvista.com \
    --to=george@mvista.com \
    --cc=ak@muc.de \
    --cc=anton@samba.org \
    --cc=davem@redhat.com \
    --cc=davidm@hpl.hp.com \
    --cc=jim.houston@ccur.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ralf@gnu.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=sfr@canb.auug.org.au \
    --cc=torvalds@transmeta.com \
    --cc=willy@debian.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;
as well as URLs for NNTP newsgroup(s).