コード例 #1
0
int smsnet_register(void)
{
	int rc;

	INIT_LIST_HEAD(&g_smsnet_clients);
	kmutex_init(&g_smsnet_clientslock);

	memset(&g_smsnet_stats, 0, sizeof(g_smsnet_stats));

	g_smsnet_device = alloc_netdev(0, "sms", smsnet_setup_device);
	if (!g_smsnet_device) {
		sms_err("alloc_netdev() failed");
		return -ENOMEM;
	}

	rc = register_netdev(g_smsnet_device);
	if (rc < 0) {
		sms_err("register_netdev() failed %d\n", rc);
		free_netdev(g_smsnet_device);
		return rc;
	}

	rc = smscore_register_hotplug(smsnet_hotplug);
	sms_info("exit - rc %d", rc);

	return rc;
}
コード例 #2
0
ファイル: n_tty.c プロジェクト: jonwchu/OS-VirtualFileSystem
/*
 * Initialize the fields of the n_tty_t struct, allocate any memory
 * you will need later, and set the tty_ldisc field of the tty.
 */
void
n_tty_attach(tty_ldisc_t *ldisc, tty_device_t *tty)
{
        /* DRIVERS {{{ */
        n_tty_t *ntty;

        KASSERT(NULL != ldisc);
        KASSERT(NULL != tty);
        KASSERT(NULL == tty->tty_ldisc);

        ntty = ldisc_to_ntty(ldisc);

        dprintf("Attaching n_tty line discipline to tty %u\n", tty->tty_id);

        kmutex_init(&ntty->ntty_rlock);
        sched_queue_init(&ntty->ntty_rwaitq);
        ntty->ntty_inbuf = (char *)kmalloc(sizeof(char) * TTY_BUF_SIZE);
        if (NULL == ntty->ntty_inbuf)
                panic("Not enough memory for n_tty input buffer\n");
        KASSERT(NULL != ntty->ntty_inbuf);

        ntty->ntty_rhead = 0;
        ntty->ntty_rawtail = 0;
        ntty->ntty_ckdtail = 0;

        tty->tty_ldisc = ldisc;

        KASSERT(n_tty_rawbuf_empty(ntty));
        KASSERT(!n_tty_rawbuf_full(ntty));
        KASSERT(n_tty_rawbuf_size(ntty) == 0);
        KASSERT(n_tty_ckdbuf_empty(ntty));
        KASSERT(n_tty_ckdbuf_size(ntty) == 0);
        /* DRIVERS }}} */
}
コード例 #3
0
ファイル: proctest.c プロジェクト: AnupreetKJohar/weenix
static void test_locking_and_cancelling(){
    dbg(DBG_TEST, "testing kmutex behavior with cancellation\n");

    kmutex_t m;
    kmutex_init(&m);

    proc_t *kmutex_proc = proc_create("kmutex_sleep_test_proc");
    kthread_t *kmutex_thread =  kthread_create(kmutex_proc, 
                                        cancellable_lock_kmutex,
                                        NULL, 
                                        (void *) &m);

    sched_make_runnable(kmutex_thread);

    kmutex_lock(&m);

    /* let kmutex_proc attempt to lock the mutex */
    yield();

    kthread_cancel(kmutex_thread, 0);

    kmutex_unlock(&m);

    int status;
    do_waitpid(kmutex_proc->p_pid, 0, &status);

    dbg(DBG_TESTPASS, "kmutex cancellation tests passed!\n");
}
コード例 #4
0
ファイル: proctest.c プロジェクト: AnupreetKJohar/weenix
static void test_normal_locking(){
    dbg(DBG_TEST, "testing normal mutex behavior\n");

    kmutex_t m;
    kmutex_init(&m);

    proc_t *kmutex_proc = proc_create("kmutex_test_proc");
    kthread_t *kmutex_thread = kthread_create(kmutex_proc, lock_kmutex_func,
                                          NULL, (void *) &m);

    sched_make_runnable(kmutex_thread);

    kmutex_lock(&m);
    
    /* let kmutex_proc attempt to lock the mutex */
    yield();

    kmutex_unlock(&m);

    /* lock and unlock the mutex with nobody on it's wait queue */
    kmutex_lock(&m);
    kmutex_unlock(&m);

    int status;
    do_waitpid(kmutex_proc->p_pid, 0, &status);

    dbg(DBG_TESTPASS, "normal kmutex tests passed!\n");
}
コード例 #5
0
ファイル: s5fs.c プロジェクト: ChenyangBai/Kernel01
/*
 * Read fs->fs_dev and set fs_op, fs_root, and fs_i.
 *
 * Point fs->fs_i to an s5fs_t*, and initialize it.  Be sure to
 * verify the superblock (using s5_check_super()).  Use vget() to get
 * the root vnode for fs_root.
 *
 * Return 0 on success, negative on failure.
 */
int
s5fs_mount(struct fs *fs)
{
        int num;
        blockdev_t *dev;
        s5fs_t *s5;
        pframe_t *vp;

        KASSERT(fs);

        if (sscanf(fs->fs_dev, "disk%d", &num) != 1) {
                return -EINVAL;
        }

        if (!(dev = blockdev_lookup(MKDEVID(1, num)))) {
                return -EINVAL;
        }

        /* allocate and initialize an s5fs_t: */
        s5 = (s5fs_t *)kmalloc(sizeof(s5fs_t));

        if (!s5)
                return -ENOMEM;

        /*     init s5f_disk: */
        s5->s5f_bdev  = dev;

        /*     init s5f_super: */
        pframe_get(S5FS_TO_VMOBJ(s5), S5_SUPER_BLOCK, &vp);

        KASSERT(vp);

        s5->s5f_super = (s5_super_t *)(vp->pf_addr);

        if (s5_check_super(s5->s5f_super)) {
                /* corrupt */
                kfree(s5);
                return -EINVAL;
        }

        pframe_pin(vp);

        /*     init s5f_mutex: */
        kmutex_init(&s5->s5f_mutex);

        /*     init s5f_fs: */
        s5->s5f_fs = fs;


        /* Init the members of fs that we (the fs-implementation) are
         * responsible for initializing: */
        fs->fs_i = s5;
        fs->fs_op = &s5fs_fsops;
        fs->fs_root = vget(fs, s5->s5f_super->s5s_root_inode);

        return 0;
}
コード例 #6
0
void *student_tests(int arg1, void *arg2) { 
	kmutex_init(&mutex);
	kmutex_init(&reader_mutex);
	kmutex_init(&writer_mutex);
    
	/* Student Test 1 */
	int rv = 0;
    int i = 0;
    dbg_print("broadcast order test");
    race2 = 0;
    for (i = 0; i < 10; i++ ) 
	start_proc("broadcast order test", broadcast_order, 0);
    
    stop_until_queued(10, &wake_me_len2);
    race2 = 0;
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len2 == 0 && "Error on wakeme bookkeeping");

    /* Student Test 2 */
    int checkVal = 0;
    dbg_print("reader writer test");
    start_proc("reader writer test", reader, 0);
    start_proc("reader writer test", reader, 0);
    start_proc("reader writer test", writer, 0);
    checkVal++;
    start_proc("reader writer test", reader, 1);
    start_proc("reader writer test", reader, 1);
    start_proc("reader writer test", reader, 1);
    start_proc("reader writer test", writer, 0);
    checkVal++;
    start_proc("reader writer test", writer, 0);
    checkVal++;
    start_proc("reader writer test", reader, 3);
    start_proc("reader writer test", reader, 3);
    wait_for_all();
    KASSERT(checkVal == rwval && "Error in Reader Writer!");

    return NULL;
}
コード例 #7
0
int smsdvb_register(void)
{
	int rc;

	INIT_LIST_HEAD(&g_smsdvb_clients);
	kmutex_init(&g_smsdvb_clientslock);

	rc = smscore_register_hotplug(smsdvb_hotplug);

	sms_debug("");

	return rc;
}
コード例 #8
0
ファイル: smsdvb-main.c プロジェクト: ReneNyffenegger/linux
static int __init smsdvb_module_init(void)
{
	int rc;

	INIT_LIST_HEAD(&g_smsdvb_clients);
	kmutex_init(&g_smsdvb_clientslock);

	smsdvb_debugfs_register();

	rc = smscore_register_hotplug(smsdvb_hotplug);

	pr_debug("\n");

	return rc;
}
コード例 #9
0
ファイル: sunghan_test.c プロジェクト: darkwowgamer/toy_OS
void *
sunghan_test(int arg1, void *arg2)
{
	int status;
	int proc_count = 0;
	pid_t proc_pid[3];

	int i;

	dbg(DBG_TEST, ">>> Start running sunghan_test()...\n");

	mynode.length = 0;
	kmutex_init(&mynode.my_mutex);
	sched_queue_init(&mynode.my_queue);

	proc_t *p1 = proc_create("add_node");
        KASSERT(NULL != p1);
	kthread_t *thr1 = kthread_create(p1, add_my_node, 0, NULL);
        KASSERT(NULL != thr1);
	sched_make_runnable(thr1);
	proc_pid[proc_count++] = p1->p_pid;

	proc_t *p2 = proc_create("remove_node");
        KASSERT(NULL != p2);
	kthread_t *thr2 = kthread_create(p2, remove_my_node, 0, NULL);
        KASSERT(NULL != thr2);
	sched_make_runnable(thr2);
	proc_pid[proc_count++] = p2->p_pid;
	
	proc_t *p3 = proc_create("watch_dog");
       	KASSERT(NULL != p3);
	kthread_t *thr3 = kthread_create(p3, watch_dog, 0, NULL);
       	KASSERT(NULL != thr3);
	sched_make_runnable(thr3);
	proc_pid[proc_count++] = p3->p_pid;
	
	for (i=0; i<2; ++i) {
		do_waitpid(proc_pid[i], 0, &status);
	}
	sched_broadcast_on(&mynode.my_queue);
	do_waitpid(proc_pid[2], 0, &status);

	while (!do_waitpid(p2->p_pid, 0, &status));

	dbg(DBG_TEST, "sunghan_test() terminated\n");

        return NULL;
}
コード例 #10
0
ファイル: fat32.c プロジェクト: darthvader88/experimentOs
filesystem *fat_mount_ramdisk(void *vaddr, u32 flags)
{
   if (flags & VFS_FS_RW)
      panic("fat_mount_ramdisk: r/w mode is NOT currently supported");

   fat_fs_device_data *d = kmalloc(sizeof(fat_fs_device_data));

   if (!d)
      return NULL;

   d->hdr = (fat_header *) vaddr;
   d->type = fat_get_type(d->hdr);
   d->cluster_size = d->hdr->BPB_SecPerClus * d->hdr->BPB_BytsPerSec;
   d->root_entry = fat_get_rootdir(d->hdr, d->type, &d->root_cluster);

   kmutex_init(&d->ex_mutex, KMUTEX_FL_RECURSIVE);

   filesystem *fs = kzmalloc(sizeof(filesystem));

   if (!fs) {
      kfree2(d, sizeof(fat_fs_device_data));
      return NULL;
   }

   fs->fs_type_name = "fat";
   fs->flags = flags;
   fs->device_id = vfs_get_new_device_id();
   fs->device_data = d;
   fs->open = fat_open;
   fs->close = fat_close;
   fs->dup = fat_dup;
   fs->getdents64 = fat_getdents64;

   fs->fs_exlock = fat_exclusive_lock;
   fs->fs_exunlock = fat_exclusive_unlock;
   fs->fs_shlock = fat_shared_lock;
   fs->fs_shunlock = fat_shared_unlock;
   return fs;
}
コード例 #11
0
ファイル: sunghan_test.c プロジェクト: darkwowgamer/toy_OS
void *
sunghan_deadlock_test(int arg1, void *arg2)
{
	int status;
	int proc_count = 0;
	pid_t proc_pid[3];

	int i;

	dbg(DBG_TEST, ">>> Start running sunghan_deadlock_test()...\n");

	mynode.length = 0;
	kmutex_init(&mynode.my_mutex);
	sched_queue_init(&mynode.my_queue);

	proc_t *p1 = proc_create("add_node");
        KASSERT(NULL != p1);
	kthread_t *thr1 = kthread_create(p1, add_my_node, 0, NULL);
        KASSERT(NULL != thr1);
	sched_make_runnable(thr1);
	proc_pid[proc_count++] = p1->p_pid;

	proc_t *p2 = proc_create("remove_node");
        KASSERT(NULL != p2);
	kthread_t *thr2 = kthread_create(p2, remove_my_node, 0, NULL);
        KASSERT(NULL != thr2);
	sched_make_runnable(thr2);
	proc_pid[proc_count++] = p2->p_pid;
	
	for (i=0; i<2; ++i) {
		do_waitpid(proc_pid[i], 0, &status);
	}
	sched_broadcast_on(&mynode.my_queue);

	dbg(DBG_TEST, "Shouldn't have gotten here in sunghan_deadlock_test().  Did NOT deadlock.\n");

        return NULL;
}
コード例 #12
0
int smschar_register(void)
{
	dev_t devno = MKDEV(smschar_major, smschar_minor);
	int rc;

	sms_info("registering device major=%d minor=%d", smschar_major,
		 smschar_minor);
	if (smschar_major) {
		rc = register_chrdev_region(devno, SMSCHAR_NR_DEVS, "smschar");
	} else {
		rc = alloc_chrdev_region(&devno, smschar_minor,
					 SMSCHAR_NR_DEVS, "smschar");
		smschar_major = MAJOR(devno);
	}

	if (rc < 0) {
		sms_warn("smschar: can't get major %d", smschar_major);
		return rc;
	}
	init_waitqueue_head(&g_pnp_event);
	kmutex_init(&g_smschar_pollwait_lock);

	return smscore_register_hotplug(smschar_hotplug);
}
コード例 #13
0
ファイル: faber_test.c プロジェクト: BennyDalby/kernel1
/* The core testproc code */
void *testproc(int arg1, void *arg2) {
    proc_thread_t pt;
    pid_t pid = -1;
    int rv = 0;
    int i = 0;

#if CS402TESTS > 0
    dbg_print("waitpid any test");
    start_proc(&pt, "waitpid any test", waitpid_test, 23);
    wait_for_any();

    dbg_print("waitpid test");
    start_proc(&pt, "waitpid test", waitpid_test, 32);
    pid = do_waitpid(2323, 0, &rv);
    if ( pid != -ECHILD ) dbg_print("Allowed wait on non-existent pid\n");
    wait_for_proc(pt.p);
/*
    dbg_print("kthread exit test");
    start_proc(&pt, "kthread exit test", kthread_exit_test, 0);
    wait_for_proc(pt.p);
*/
/*
    dbg_print("many test");
    for (i = 0; i < 10; i++) 
	start_proc(NULL, "many test", waitpid_test, i);
    wait_for_all();a
*/
#endif

#if CS402TESTS > 1
    dbg_print("Context switch test");
    start_proc(&pt, "Context switch", racer_test, 0);
    wait_for_proc(pt.p);
#endif

#if CS402TESTS > 2
    sched_queue_init(&wake_me_q);

    dbg_print("wake me test");
    wake_me_len = 0;
    start_proc(&pt, "wake me test", wakeme_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("broadcast me test");
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "broadcast me test", wakeme_test, 0);
    stop_until_queued(10, &wake_me_len);
    /* Make sure the processes have blocked */
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 3
    dbg_print("wake me uncancellable test");
    start_proc(&pt, "wake me uncancellable test", 
	    wakeme_uncancellable_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("broadcast me uncancellable test");
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "broadcast me uncancellable test", 
		wakeme_uncancellable_test, 0);
    /* Make sure the processes have blocked */
    stop_until_queued(10, &wake_me_len);
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 4
    dbg_print("cancel me test");
    start_proc(&pt, "cancel me test", cancelme_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_cancel(pt.t);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("prior cancel me test");
    start_proc(&pt, "prior cancel me test", cancelme_test, 0);
    /*  Cancel before sleep */
    sched_cancel(pt.t);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("cancel me head test");
    start_proc(&pt, "cancel me head test", cancelme_test, 0);
    start_proc(NULL, "cancel me head test", wakeme_test, 0);
    stop_until_queued(2, &wake_me_len);
    sched_cancel(pt.t);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
    
    dbg_print("cancel me tail test");
    start_proc(NULL, "cancel me tail test", wakeme_test, 0);
    start_proc(&pt, "cancel me tail test", cancelme_test, 0);
    stop_until_queued(2, &wake_me_len);
    sched_cancel(pt.t);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 5
    dbg_print("Reparenting test");
    start_proc(NULL, "Reparenting test", reparent_test, 1);
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    stop_until_zero(&wake_me_len);
    dbg_print("Reparenting stress test");
    start_proc(NULL, "Reparenting stress test", reparent_test, 10);
    stop_until_queued(10, &wake_me_len);
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    stop_until_zero(&wake_me_len);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 6
    kmutex_init(&mutex);

    dbg_print("show race test");
    race = 0;
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "show race test", racer_test, 0);
    wait_for_all();

    dbg_print("fix race test");
    race = 0;
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "fix race test", mutex_uncancellable_test, 0);
    wait_for_all();

    dbg_print("fix race test w/cancel");
    race = 0;
    for (i = 0; i < 10; i++ ) {
	if ( i % 2 == 0) { 
	    start_proc(NULL, "fix race test w/cancel", mutex_test, 0);
	} else {
	    start_proc(&pt, "fix race test w/cancel", mutex_test_cancelme, 0);
	    sched_cancel(pt.t);
	}
    }
    wait_for_all();
#endif

#if CS402TESTS > 7
    dbg_print("kill all test");
    for ( i=0 ; i < 10; i++ )
	start_proc(NULL, "kill all test", cancelme_test, 0);
    stop_until_queued(10, &wake_me_len);
    proc_kill_all();
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 8
    student_tests(arg1, arg2);
#endif

    dbg_print("All tests completed\n\n");
    return NULL;
}