📄 qsnet-suse-2.6.patch
字号:
+/* IOPROC SYNC PAGE+ *+ * Called when a memory map is synchronised with its disk image i.e. when the + * msync() syscall is invoked. Any future read or write to the associated page+ * by the IOPROC should cause the page to be marked as referenced or modified.+ *+ * Not currently called as msync() calls ioproc_sync_range() instead+ *+ * Called holding the mm->page_table_lock+ */+static inline void +ioproc_sync_page(struct vm_area_struct *vma, unsigned long addr)+{+ struct ioproc_ops *cp;++ for (cp = vma->vm_mm->ioproc_ops; cp; cp = cp->next)+ if (cp->sync_page)+ cp->sync_page(cp->arg, vma, addr);+}++/* IOPROC INVALIDATE PAGE+ *+ * Called whenever a valid PTE is unloaded e.g. when a page is unmapped by the+ * user or paged out by the kernel. + *+ * After this call the IOPROC must not access the physical memory again unless+ * a new translation is loaded.+ *+ * Called holding the mm->page_table_lock+ */+static inline void +ioproc_invalidate_page(struct vm_area_struct *vma, unsigned long addr)+{+ struct ioproc_ops *cp;++ for (cp = vma->vm_mm->ioproc_ops; cp; cp = cp->next)+ if (cp->invalidate_page)+ cp->invalidate_page(cp->arg, vma, addr);+}++/* IOPROC UPDATE PAGE+ *+ * Called whenever a valid PTE is loaded e.g. mmaping memory, moving the brk + * up, when breaking COW or faulting in an anoymous page of memory.+ *+ * These give the IOPROC device the opportunity to load translations + * speculatively, which can improve performance by avoiding device translation+ * faults.+ *+ * Called holding the mm->page_table_lock+ */+static inline void +ioproc_update_page(struct vm_area_struct *vma, unsigned long addr)+{+ struct ioproc_ops *cp;++ for (cp = vma->vm_mm->ioproc_ops; cp; cp = cp->next)+ if (cp->update_page)+ cp->update_page(cp->arg, vma, addr);+}++#else++/* ! CONFIG_IOPROC so make all hooks empty */++#define ioproc_release(mm) do { } while (0)++#define ioproc_sync_range(vma,start,end) do { } while (0)++#define ioproc_invalidate_range(vma, start,end) do { } while (0)++#define ioproc_update_range(vma, start, end) do { } while (0)++#define ioproc_change_protection(vma, start, end, prot) do { } while (0)++#define ioproc_sync_page(vma, addr) do { } while (0)++#define ioproc_invalidate_page(vma, addr) do { } while (0)++#define ioproc_update_page(vma, addr) do { } while (0)++#endif /* CONFIG_IOPROC */++#endif /* __LINUX_IOPROC_H__ */Index: LINUX-SRC-TREE/include/linux/ptrack.h===================================================================--- /dev/null+++ LINUX-SRC-TREE/include/linux/ptrack.h@@ -0,0 +1,65 @@+/*+ * Copyright (C) 2000 Regents of the University of California+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ *+ * Derived from exit_actn.c by+ * Copyright (C) 2003 Quadrics Ltd.+ *+ */+#ifndef __LINUX_PTRACK_H+#define __LINUX_PTRACK_H++/* + * Process tracking - this allows a module to keep track of processes+ * in order that it can manage all tasks derived from a single process.+ */++#define PTRACK_PHASE_CLONE 1+#define PTRACK_PHASE_CLONE_FAIL 2+#define PTRACK_PHASE_EXEC 3+#define PTRACK_PHASE_EXIT 4++#define PTRACK_FINISHED 0+#define PTRACK_INNHERIT 1+#define PTRACK_DENIED 2++#ifdef CONFIG_PTRACK++typedef int (*ptrack_callback_t)(void *arg, int phase, struct task_struct *child);++struct ptrack_desc {+ struct list_head link;+ ptrack_callback_t callback;+ void *arg;+};++extern int ptrack_register (ptrack_callback_t callback, void *arg);+extern void ptrack_deregister (ptrack_callback_t callback, void *arg);+extern int ptrack_registered (ptrack_callback_t callback, void *arg);++extern int ptrack_call_callbacks (int phase, struct task_struct *child);++#define INIT_TASK_PTRACK(tsk) \+ .ptrack_list = LIST_HEAD_INIT(tsk.ptrack_list)++#else+#define ptrack_call_callbacks (phase, child) (0)++#define INIT_TASK_PTRACK(tsk)++#endif++#endif /* __LINUX_PTRACK_H */Index: LINUX-SRC-TREE/include/linux/sched.h===================================================================--- LINUX-SRC-TREE.orig/include/linux/sched.h+++ LINUX-SRC-TREE/include/linux/sched.h@@ -188,6 +188,9 @@ asmlinkage void schedule(void); extern int max_timeslice, min_timeslice; struct namespace;+#ifdef CONFIG_IOPROC+struct ioproc_ops;+#endif /* Maximum number of active map areas.. This is a random (large) number */ #define DEFAULT_MAX_MAP_COUNT 65536@@ -241,6 +244,11 @@ struct mm_struct { struct kioctx default_kioctx; unsigned long hiwater_rss, hiwater_vm;++#ifdef CONFIG_IOPROC+ /* hooks for io devices with advanced RDMA capabilities */+ struct ioproc_ops *ioproc_ops;+#endif }; extern int mmlist_nr;@@ -603,6 +611,10 @@ struct task_struct { struct rw_semaphore pagg_sem; #endif +#ifdef CONFIG_PTRACK+/* process tracking callback */+ struct list_head ptrack_list;+#endif }; static inline pid_t process_group(struct task_struct *tsk)Index: LINUX-SRC-TREE/ipc/shm.c===================================================================--- LINUX-SRC-TREE.orig/ipc/shm.c+++ LINUX-SRC-TREE/ipc/shm.c@@ -27,6 +27,7 @@ #include <linux/shmem_fs.h> #include <linux/security.h> #include <linux/audit.h>+#include <linux/module.h> #include <linux/trigevent_hooks.h> #include <asm/uaccess.h> @@ -879,6 +880,44 @@ asmlinkage long sys_shmdt(char __user *s return audit_result(retval); } +/*+ * Mark all segments created by this process for destruction+ */+int shm_cleanup (void)+{+ int i;++ down(&shm_ids.sem);++ for (i = 0; i <= shm_ids.max_id; i++) {+ struct shmid_kernel *shp;++ shp = shm_lock(i);+ if (shp != NULL) {+ /* mark this segment for destruction if we created it */+ if (current->pid == shp->shm_cprid)+ {+ /* copy of IPC_RMID code */+ if (shp->shm_nattch) {+ shp->shm_flags |= SHM_DEST;+ /* do not find it any more */+ shp->shm_perm.key = IPC_PRIVATE;+ } else {+ shm_destroy(shp);+ continue;+ }+ }++ shm_unlock(shp);+ }+ }++ up(&shm_ids.sem);++ return 0;+}+EXPORT_SYMBOL_GPL(shm_cleanup);+ #ifdef CONFIG_PROC_FS static int sysvipc_shm_read_proc(char *buffer, char **start, off_t offset, int length, int *eof, void *data) {Index: LINUX-SRC-TREE/kernel/exit.c===================================================================--- LINUX-SRC-TREE.orig/kernel/exit.c+++ LINUX-SRC-TREE/kernel/exit.c@@ -40,6 +40,8 @@ /* tng related changes */ int (*tng_exitfunc)(int) = NULL; +#include <linux/ptrack.h>+ extern void sem_exit (void); extern struct task_struct *child_reaper; void (*do_eop_acct) (int, struct task_struct *);@@ -848,6 +850,8 @@ asmlinkage NORET_TYPE void do_exit(long audit_exit(tsk, code); audit_free(tsk->audit); #endif+ /* Notify any ptrack callbacks of the process exit */+ ptrack_call_callbacks (PTRACK_PHASE_EXIT, NULL); __exit_mm(tsk); if (unlikely(tng_exitfunc))Index: LINUX-SRC-TREE/kernel/fork.c===================================================================--- LINUX-SRC-TREE.orig/kernel/fork.c+++ LINUX-SRC-TREE/kernel/fork.c@@ -14,6 +14,7 @@ #include <linux/config.h> #include <linux/slab.h> #include <linux/init.h>+#include <linux/ptrack.h> #include <linux/unistd.h> #include <linux/smp_lock.h> #include <linux/module.h>@@ -432,6 +433,9 @@ static struct mm_struct * mm_init(struct mm->page_table_lock = SPIN_LOCK_UNLOCKED; mm->ioctx_list_lock = RW_LOCK_UNLOCKED; mm->ioctx_list = NULL;+#ifdef CONFIG_IOPROC+ mm->ioproc_ops = NULL;+#endif mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm); mm->free_area_cache = TASK_UNMAPPED_BASE; @@ -1276,6 +1280,11 @@ long do_fork(unsigned long clone_flags, audit_fork(current, p); #endif + if (ptrack_call_callbacks(PTRACK_PHASE_CLONE, p)) {+ sigaddset(&p->pending.signal, SIGKILL);+ set_tsk_thread_flag(p, TIF_SIGPENDING);+ }+ /* Trace the event */ TRIG_EVENT(fork_hook, clone_flags, p, pid); if (!(clone_flags & CLONE_STOPPED)) {Index: LINUX-SRC-TREE/kernel/Kconfig===================================================================--- /dev/null+++ LINUX-SRC-TREE/kernel/Kconfig@@ -0,0 +1,14 @@+#+# Kernel subsystem specific config+# ++# Support for Process Tracking callbacks+#+config PTRACK+ bool "Enable PTRACK process tracking hooks"+ default y+ help+ This option enables hooks to be called when processes are+ created and destoryed in order for a resource management + system to know which processes are a member of a "job" and + to be able to clean up when the job is terminated.Index: LINUX-SRC-TREE/kernel/Makefile===================================================================--- LINUX-SRC-TREE.orig/kernel/Makefile+++ LINUX-SRC-TREE/kernel/Makefile@@ -29,6 +29,7 @@ obj-$(CONFIG_LTT) += ltt/ obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CKRM_CPU_SCHEDULE) += ckrm_classqueue.o ckrm_sched.o+obj-$(CONFIG_PTRACK) += ptrack.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer isIndex: LINUX-SRC-TREE/kernel/ptrack.c===================================================================--- /dev/null+++ LINUX-SRC-TREE/kernel/ptrack.c@@ -0,0 +1,145 @@+/*+ * Copyright (C) 2000 Regents of the University of California+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ *+ * Derived from exit_actn.c by+ * Copyright (C) 2003 Quadrics Ltd.+ */+++#include <linux/module.h>+#include <linux/spinlock.h>+#include <linux/sched.h>+#include <linux/ptrack.h>+#include <linux/slab.h>+#include <linux/list.h>++#include <asm/errno.h>++int+ptrack_register (ptrack_callback_t callback, void *arg)+{+ struct ptrack_desc *desc = kmalloc (sizeof (struct ptrack_desc), GFP_KERNEL);+ + if (desc == NULL)+ return -ENOMEM;++ desc->callback = callback;+ desc->arg = arg;+ + list_add_tail (&desc->link, ¤t->ptrack_list);+ + return 0;+}++void+ptrack_deregister (ptrack_callback_t callback, void *arg)+{ + struct list_head *el, *nel;+ + list_for_each_safe (el, nel, ¤t->ptrack_list) {+ struct ptrack_desc *desc = list_entry (el, struct ptrack_desc, link);+ + if (desc->callback == callback && desc->arg == arg) {+ list_del (&desc->link);+ kfree (desc);+ }+ }+}++int+ptrack_registered (ptrack_callback_t callback, void *arg)+{+ struct list_head *el;+ + list_for_each (el, ¤t->ptrack_list) {+ struct ptrack_desc *desc = list_entry (el, struct ptrack_desc, link);+ + if (desc->callback == callback && desc->arg == arg)+ return 1;+ }+ return 0;+} + +int+ptrack_call_callbacks (int phase, struct task_struct *child)+{+ struct list_head *el, *nel;+ struct ptrack_desc *new;+ int res;+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -