⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sched.h

📁 中科院徐志伟老师一书《操作系统 原理·技术与编程》的源代码和习题接
💻 H
📖 第 1 页 / 共 2 页
字号:
    sigpending:		0,						\    addr_limit:		KERNEL_DS,					\    exec_domain:	&default_exec_domain,				\    lock_depth:		-1,						\    counter:		DEF_COUNTER,					\    nice:		DEF_NICE,					\    policy:		SCHED_OTHER,					\    mm:			NULL,						\    active_mm:		&init_mm,					\    cpus_runnable:	-1,						\    cpus_allowed:	-1,						\    run_list:		LIST_HEAD_INIT(tsk.run_list),			\    next_task:		&tsk,						\    prev_task:		&tsk,						\    p_opptr:		&tsk,						\    p_pptr:		&tsk,						\    thread_group:	LIST_HEAD_INIT(tsk.thread_group),		\    wait_chldexit:	__WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\    real_timer:		{						\	function:		it_real_fn				\    },									\    cap_effective:	CAP_INIT_EFF_SET,				\    cap_inheritable:	CAP_INIT_INH_SET,				\    cap_permitted:	CAP_FULL_SET,					\    keep_capabilities:	0,						\    rlim:		INIT_RLIMITS,					\    user:		INIT_USER,					\    comm:		"swapper",					\    thread:		INIT_THREAD,					\    fs:			&init_fs,					\    files:		&init_files,					\    sigmask_lock:	SPIN_LOCK_UNLOCKED,				\    sig:		&init_signals,					\    pending:		{ NULL, &tsk.pending.head, {{0}}},		\    blocked:		{{0}},						\    alloc_lock:		SPIN_LOCK_UNLOCKED,				\    journal_info:	NULL,						\}#ifndef INIT_TASK_SIZE# define INIT_TASK_SIZE	2048*sizeof(long)#endifunion task_union {	struct task_struct task;	unsigned long stack[INIT_TASK_SIZE/sizeof(long)];};extern union task_union init_task_union;extern struct   mm_struct init_mm;extern struct task_struct *init_tasks[NR_CPUS];/* PID hashing. (shouldnt this be dynamic?) */#define PIDHASH_SZ (4096 >> 2)extern struct task_struct *pidhash[PIDHASH_SZ];#define pid_hashfn(x)	((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))static inline void hash_pid(struct task_struct *p){	struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];	if((p->pidhash_next = *htable) != NULL)		(*htable)->pidhash_pprev = &p->pidhash_next;	*htable = p;	p->pidhash_pprev = htable;}static inline void unhash_pid(struct task_struct *p){	if(p->pidhash_next)		p->pidhash_next->pidhash_pprev = p->pidhash_pprev;	*p->pidhash_pprev = p->pidhash_next;}static inline struct task_struct *find_task_by_pid(int pid){	struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];	for(p = *htable; p && p->pid != pid; p = p->pidhash_next)		;	return p;}#define task_has_cpu(tsk) ((tsk)->cpus_runnable != ~0UL)static inline void task_set_cpu(struct task_struct *tsk, unsigned int cpu){	tsk->processor = cpu;	tsk->cpus_runnable = 1UL << cpu;}static inline void task_release_cpu(struct task_struct *tsk){	tsk->cpus_runnable = ~0UL;}/* per-UID process charging. */extern struct user_struct * alloc_uid(uid_t);extern void free_uid(struct user_struct *);#include <asm/current.h>extern unsigned long volatile jiffies;extern unsigned long itimer_ticks;extern unsigned long itimer_next;extern struct timeval xtime;extern void do_timer(struct pt_regs *);extern unsigned int * prof_buffer;extern unsigned long prof_len;extern unsigned long prof_shift;#define CURRENT_TIME (xtime.tv_sec)extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, int nr));extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr));extern void FASTCALL(sleep_on(wait_queue_head_t *q));extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,				      signed long timeout));extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,						    signed long timeout));extern int FASTCALL(wake_up_process(struct task_struct * tsk));#define wake_up(x)			__wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1)#define wake_up_nr(x, nr)		__wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr)#define wake_up_all(x)			__wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0)#define wake_up_sync(x)			__wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1)#define wake_up_sync_nr(x, nr)		__wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr)#define wake_up_interruptible(x)	__wake_up((x),TASK_INTERRUPTIBLE, 1)#define wake_up_interruptible_nr(x, nr)	__wake_up((x),TASK_INTERRUPTIBLE, nr)#define wake_up_interruptible_all(x)	__wake_up((x),TASK_INTERRUPTIBLE, 0)#define wake_up_interruptible_sync(x)	__wake_up_sync((x),TASK_INTERRUPTIBLE, 1)#define wake_up_interruptible_sync_nr(x) __wake_up_sync((x),TASK_INTERRUPTIBLE,  nr)asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);extern int in_group_p(gid_t);extern int in_egroup_p(gid_t);extern void proc_caches_init(void);extern void flush_signals(struct task_struct *);extern void flush_signal_handlers(struct task_struct *);extern int dequeue_signal(sigset_t *, siginfo_t *);extern void block_all_signals(int (*notifier)(void *priv), void *priv,			      sigset_t *mask);extern void unblock_all_signals(void);extern int send_sig_info(int, struct siginfo *, struct task_struct *);extern int force_sig_info(int, struct siginfo *, struct task_struct *);extern int kill_pg_info(int, struct siginfo *, pid_t);extern int kill_sl_info(int, struct siginfo *, pid_t);extern int kill_proc_info(int, struct siginfo *, pid_t);extern void notify_parent(struct task_struct *, int);extern void do_notify_parent(struct task_struct *, int);extern void force_sig(int, struct task_struct *);extern int send_sig(int, struct task_struct *, int);extern int kill_pg(pid_t, int, int);extern int kill_sl(pid_t, int, int);extern int kill_proc(pid_t, int, int);extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);static inline int signal_pending(struct task_struct *p){	return (p->sigpending != 0);}/* * Re-calculate pending state from the set of locally pending * signals, globally pending signals, and blocked signals. */static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked){	unsigned long ready;	long i;	switch (_NSIG_WORDS) {	default:		for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)			ready |= signal->sig[i] &~ blocked->sig[i];		break;	case 4: ready  = signal->sig[3] &~ blocked->sig[3];		ready |= signal->sig[2] &~ blocked->sig[2];		ready |= signal->sig[1] &~ blocked->sig[1];		ready |= signal->sig[0] &~ blocked->sig[0];		break;	case 2: ready  = signal->sig[1] &~ blocked->sig[1];		ready |= signal->sig[0] &~ blocked->sig[0];		break;	case 1: ready  = signal->sig[0] &~ blocked->sig[0];	}	return ready !=	0;}/* Reevaluate whether the task has signals pending delivery.   This is required every time the blocked sigset_t changes.   All callers should have t->sigmask_lock.  */static inline void recalc_sigpending(struct task_struct *t){	t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);}/* True if we are on the alternate signal stack.  */static inline int on_sig_stack(unsigned long sp){	return (sp - current->sas_ss_sp < current->sas_ss_size);}static inline int sas_ss_flags(unsigned long sp){	return (current->sas_ss_size == 0 ? SS_DISABLE		: on_sig_stack(sp) ? SS_ONSTACK : 0);}extern int request_irq(unsigned int,		       void (*handler)(int, void *, struct pt_regs *),		       unsigned long, const char *, void *);extern void free_irq(unsigned int, void *);/* * This has now become a routine instead of a macro, it sets a flag if * it returns true (to do BSD-style accounting where the process is flagged * if it uses root privs). The implication of this is that you should do * normal permissions checks first, and check suser() last. * * [Dec 1997 -- Chris Evans] * For correctness, the above considerations need to be extended to * fsuser(). This is done, along with moving fsuser() checks to be * last. * * These will be removed, but in the mean time, when the SECURE_NOROOT  * flag is set, uids don't grant privilege. */static inline int suser(void){	if (!issecure(SECURE_NOROOT) && current->euid == 0) { 		current->flags |= PF_SUPERPRIV;		return 1;	}	return 0;}static inline int fsuser(void){	if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {		current->flags |= PF_SUPERPRIV;		return 1;	}	return 0;}/* * capable() checks for a particular capability.   * New privilege checks should use this interface, rather than suser() or * fsuser(). See include/linux/capability.h for defined capabilities. */static inline int capable(int cap){#if 1 /* ok now */	if (cap_raised(current->cap_effective, cap))#else	if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)#endif	{		current->flags |= PF_SUPERPRIV;		return 1;	}	return 0;}/* * Routines for handling mm_structs */extern struct mm_struct * mm_alloc(void);extern struct mm_struct * start_lazy_tlb(void);extern void end_lazy_tlb(struct mm_struct *mm);/* mmdrop drops the mm and the page tables */extern inline void FASTCALL(__mmdrop(struct mm_struct *));static inline void mmdrop(struct mm_struct * mm){	if (atomic_dec_and_test(&mm->mm_count))		__mmdrop(mm);}/* mmput gets rid of the mappings and all user-space */extern void mmput(struct mm_struct *);/* Remove the current tasks stale references to the old mm_struct */extern void mm_release(void);/* * Routines for handling the fd arrays */extern struct file ** alloc_fd_array(int);extern int expand_fd_array(struct files_struct *, int nr);extern void free_fd_array(struct file **, int);extern fd_set *alloc_fdset(int);extern int expand_fdset(struct files_struct *, int nr);extern void free_fdset(fd_set *, int);extern int  copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);extern void flush_thread(void);extern void exit_thread(void);extern void exit_mm(struct task_struct *);extern void exit_files(struct task_struct *);extern void exit_sighand(struct task_struct *);extern void reparent_to_init(void);extern void daemonize(void);extern int do_execve(char *, char **, char **, struct pt_regs *);extern int do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long);extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));#define __wait_event(wq, condition) 					\do {									\	wait_queue_t __wait;						\	init_waitqueue_entry(&__wait, current);				\									\	add_wait_queue(&wq, &__wait);					\	for (;;) {							\		set_current_state(TASK_UNINTERRUPTIBLE);		\		if (condition)						\			break;						\		schedule();						\	}								\	current->state = TASK_RUNNING;					\	remove_wait_queue(&wq, &__wait);				\} while (0)#define wait_event(wq, condition) 					\do {									\	if (condition)	 						\		break;							\	__wait_event(wq, condition);					\} while (0)#define __wait_event_interruptible(wq, condition, ret)			\do {									\	wait_queue_t __wait;						\	init_waitqueue_entry(&__wait, current);				\									\	add_wait_queue(&wq, &__wait);					\	for (;;) {							\		set_current_state(TASK_INTERRUPTIBLE);			\		if (condition)						\			break;						\		if (!signal_pending(current)) {				\			schedule();					\			continue;					\		}							\		ret = -ERESTARTSYS;					\		break;							\	}								\	current->state = TASK_RUNNING;					\	remove_wait_queue(&wq, &__wait);				\} while (0)	#define wait_event_interruptible(wq, condition)				\({									\	int __ret = 0;							\	if (!(condition))						\		__wait_event_interruptible(wq, condition, __ret);	\	__ret;								\})#define REMOVE_LINKS(p) do { \	(p)->next_task->prev_task = (p)->prev_task; \	(p)->prev_task->next_task = (p)->next_task; \	if ((p)->p_osptr) \		(p)->p_osptr->p_ysptr = (p)->p_ysptr; \	if ((p)->p_ysptr) \		(p)->p_ysptr->p_osptr = (p)->p_osptr; \	else \		(p)->p_pptr->p_cptr = (p)->p_osptr; \	} while (0)#define SET_LINKS(p) do { \	(p)->next_task = &init_task; \	(p)->prev_task = init_task.prev_task; \	init_task.prev_task->next_task = (p); \	init_task.prev_task = (p); \	(p)->p_ysptr = NULL; \	if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \		(p)->p_osptr->p_ysptr = p; \	(p)->p_pptr->p_cptr = p; \	} while (0)#define for_each_task(p) \	for (p = &init_task ; (p = p->next_task) != &init_task ; )#define next_thread(p) \	list_entry((p)->thread_group.next, struct task_struct, thread_group)static inline void del_from_runqueue(struct task_struct * p){	nr_running--;	p->sleep_time = jiffies;	list_del(&p->run_list);	p->run_list.next = NULL;}static inline int task_on_runqueue(struct task_struct *p){	return (p->run_list.next != NULL);}static inline void unhash_process(struct task_struct *p){	if (task_on_runqueue(p)) BUG();	write_lock_irq(&tasklist_lock);	nr_threads--;	unhash_pid(p);	REMOVE_LINKS(p);	list_del(&p->thread_group);	write_unlock_irq(&tasklist_lock);}/* Protects ->fs, ->files, ->mm, and synchronises with wait4().  Nests inside tasklist_lock */static inline void task_lock(struct task_struct *p){	spin_lock(&p->alloc_lock);}static inline void task_unlock(struct task_struct *p){	spin_unlock(&p->alloc_lock);}/* write full pathname into buffer and return start of pathname */static inline char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,				char *buf, int buflen){	char *res;	struct vfsmount *rootmnt;	struct dentry *root;	read_lock(&current->fs->lock);	rootmnt = mntget(current->fs->rootmnt);	root = dget(current->fs->root);	read_unlock(&current->fs->lock);	spin_lock(&dcache_lock);	res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);	spin_unlock(&dcache_lock);	dput(root);	mntput(rootmnt);	return res;}#endif /* __KERNEL__ */#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -