KSE/ia64 & thr_spinlock.c:1.18: problem identified

Marcel Moolenaar marcel at xcllnt.net
Wed Nov 26 21:55:48 PST 2003


Ok,

I found what the problem is. Syscalls that got interrupted were not
restarted when they should be. This is the result of using the KSE
internal context functions, when we should be going through the
kernel. So, the end result is that we do in fact need a syscall to
switch KSE contexts. Attached a patch to add such syscall. Please
review (ia64 specific changes to make use of the syscall are not
included).

FYI,

-- 
 Marcel Moolenaar	  USPA: A-39004		 marcel at xcllnt.net
-------------- next part --------------
Index: kern/init_sysent.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/init_sysent.c,v
retrieving revision 1.161
diff -u -r1.161 init_sysent.c
--- kern/init_sysent.c	14 Nov 2003 03:49:41 -0000	1.161
+++ kern/init_sysent.c	27 Nov 2003 01:17:38 -0000
@@ -2,7 +2,7 @@
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/kern/init_sysent.c,v 1.161 2003/11/14 03:49:41 jeff Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.158 2003/11/14 03:48:37 jeff Exp 
  */
 
@@ -468,4 +468,5 @@
 	{ AS(extattr_list_fd_args), (sy_call_t *)extattr_list_fd },	/* 437 = extattr_list_fd */
 	{ AS(extattr_list_file_args), (sy_call_t *)extattr_list_file },	/* 438 = extattr_list_file */
 	{ AS(extattr_list_link_args), (sy_call_t *)extattr_list_link },	/* 439 = extattr_list_link */
+	{ SYF_MPSAFE | AS(kse_switchin_args), (sy_call_t *)kse_switchin },	/* 440 = kse_switchin */
 };
Index: kern/kern_thread.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_thread.c,v
retrieving revision 1.162
diff -u -r1.162 kern_thread.c
--- kern/kern_thread.c	11 Nov 2003 22:07:29 -0000	1.162
+++ kern/kern_thread.c	27 Nov 2003 01:22:08 -0000
@@ -384,6 +384,30 @@
 	thread_link(td, kg);
 }
 
+#ifndef _SYS_SYSPROTO_H_
+struct kse_switchin_args {
+	const struct __mcontext *mcp;
+	long val;
+	long *loc;
+};
+#endif
+
+int
+kse_switchin(struct thread *td, struct kse_switchin_args *uap)
+{
+	mcontext_t mc;
+	int error;
+
+	error = (uap->mcp == NULL) ? EINVAL : 0;
+	if (!error)
+		error = copyin(uap->mcp, &mc, sizeof(mc));
+	if (!error)
+		error = set_mcontext(td, &mc);
+	if (!error && uap->loc != NULL)
+		suword(uap->loc, uap->val);
+	return ((error == 0) ? EJUSTRETURN : error);
+}
+
 /*
 struct kse_thr_interrupt_args {
 	struct kse_thr_mailbox * tmbx;
Index: kern/syscalls.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/syscalls.c,v
retrieving revision 1.147
diff -u -r1.147 syscalls.c
--- kern/syscalls.c	14 Nov 2003 03:49:41 -0000	1.147
+++ kern/syscalls.c	27 Nov 2003 01:17:38 -0000
@@ -2,7 +2,7 @@
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/kern/syscalls.c,v 1.147 2003/11/14 03:49:41 jeff Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.158 2003/11/14 03:48:37 jeff Exp 
  */
 
@@ -447,4 +447,5 @@
 	"extattr_list_fd",			/* 437 = extattr_list_fd */
 	"extattr_list_file",			/* 438 = extattr_list_file */
 	"extattr_list_link",			/* 439 = extattr_list_link */
+	"kse_switchin",			/* 440 = kse_switchin */
 };
Index: kern/syscalls.master
===================================================================
RCS file: /home/ncvs/src/sys/kern/syscalls.master,v
retrieving revision 1.158
diff -u -r1.158 syscalls.master
--- kern/syscalls.master	14 Nov 2003 03:48:37 -0000	1.158
+++ kern/syscalls.master	27 Nov 2003 01:16:01 -0000
@@ -639,6 +639,8 @@
 			    int attrnamespace, void *data, size_t nbytes); }
 439	STD	BSD	{ ssize_t extattr_list_link(const char *path, \
 			    int attrnamespace, void *data, size_t nbytes); }
+440	MSTD	BSD	{ int kse_switchin(const struct __mcontext *mcp, \
+			    long val, long *loc); }
 
 ; Please copy any additions and changes to the following compatability tables:
 ; sys/ia64/ia32/syscalls.master  (take a best guess)
Index: sys/kse.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/kse.h,v
retrieving revision 1.19
diff -u -r1.19 kse.h
--- sys/kse.h	5 Aug 2003 12:00:55 -0000	1.19
+++ sys/kse.h	27 Nov 2003 03:24:00 -0000
@@ -109,6 +109,7 @@
 int	kse_release(struct timespec *);
 int	kse_thr_interrupt(struct kse_thr_mailbox *, int, long);
 int	kse_wakeup(struct kse_mailbox *);
+int	kse_switchin(mcontext_t *, long, long *);
 #endif	/* !_KERNEL */
 
 #endif	/* !_SYS_KSE_H_ */
Index: sys/syscall.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/syscall.h,v
retrieving revision 1.145
diff -u -r1.145 syscall.h
--- sys/syscall.h	14 Nov 2003 03:49:41 -0000	1.145
+++ sys/syscall.h	27 Nov 2003 01:17:38 -0000
@@ -2,7 +2,7 @@
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/sys/syscall.h,v 1.145 2003/11/14 03:49:41 jeff Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.158 2003/11/14 03:48:37 jeff Exp 
  */
 
@@ -351,4 +351,5 @@
 #define	SYS_extattr_list_fd	437
 #define	SYS_extattr_list_file	438
 #define	SYS_extattr_list_link	439
-#define	SYS_MAXSYSCALL	440
+#define	SYS_kse_switchin	440
+#define	SYS_MAXSYSCALL	441
Index: sys/syscall.mk
===================================================================
RCS file: /home/ncvs/src/sys/sys/syscall.mk,v
retrieving revision 1.100
diff -u -r1.100 syscall.mk
--- sys/syscall.mk	14 Nov 2003 03:49:41 -0000	1.100
+++ sys/syscall.mk	27 Nov 2003 01:17:38 -0000
@@ -1,6 +1,6 @@
 # FreeBSD system call names.
 # DO NOT EDIT-- this file is automatically generated.
-# $FreeBSD: src/sys/sys/syscall.mk,v 1.100 2003/11/14 03:49:41 jeff Exp $
+# $FreeBSD$
 # created from FreeBSD: src/sys/kern/syscalls.master,v 1.158 2003/11/14 03:48:37 jeff Exp 
 MIASM =  \
 	syscall.o \
@@ -292,4 +292,5 @@
 	jail_attach.o \
 	extattr_list_fd.o \
 	extattr_list_file.o \
-	extattr_list_link.o
+	extattr_list_link.o \
+	kse_switchin.o
Index: sys/sysproto.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/sysproto.h,v
retrieving revision 1.141
diff -u -r1.141 sysproto.h
--- sys/sysproto.h	14 Nov 2003 03:49:41 -0000	1.141
+++ sys/sysproto.h	27 Nov 2003 01:17:38 -0000
@@ -2,7 +2,7 @@
  * System call prototypes.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/sys/sysproto.h,v 1.141 2003/11/14 03:49:41 jeff Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.158 2003/11/14 03:48:37 jeff Exp 
  */
 
@@ -1284,6 +1284,11 @@
 	char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)];
 	char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
 };
+struct kse_switchin_args {
+	char mcp_l_[PADL_(const struct __mcontext *)]; const struct __mcontext * mcp; char mcp_r_[PADR_(const struct __mcontext *)];
+	char val_l_[PADL_(long)]; long val; char val_r_[PADR_(long)];
+	char loc_l_[PADL_(long *)]; long * loc; char loc_r_[PADR_(long *)];
+};
 int	nosys(struct thread *, struct nosys_args *);
 void	sys_exit(struct thread *, struct sys_exit_args *);
 int	fork(struct thread *, struct fork_args *);
@@ -1573,6 +1578,7 @@
 int	extattr_list_fd(struct thread *, struct extattr_list_fd_args *);
 int	extattr_list_file(struct thread *, struct extattr_list_file_args *);
 int	extattr_list_link(struct thread *, struct extattr_list_link_args *);
+int	kse_switchin(struct thread *, struct kse_switchin_args *);
 
 #ifdef COMPAT_43
 


More information about the freebsd-threads mailing list