OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [test_suite0/] [src/] [api/] [smp.c] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Some minimal tests for SMP functionality
3
 *
4
 * Copyright (C) 2010 B Labs Ltd.
5
 *
6
 * Author: Bahadir Balban
7
 */
8
#include <l4lib/exregs.h>
9
#include <l4lib/lib/thread.h>
10
#include <stdio.h>
11
#include <string.h>
12
#include <tests.h>
13
 
14
static int new_thread_func(void *args)
15
{
16
        struct exregs_data exregs;
17
        struct task_ids ids;
18
        int err;
19
 
20
        l4_getid(&ids);
21
 
22
#if 0
23
        memset(&exregs, 0, sizeof(exregs));
24
        exregs_set_read(&exregs);
25
        if ((err = l4_exchange_registers(&exregs,
26
                                         ids.tid)) < 0) {
27
                printf("SMP test: Exregs call failed on %s\n",
28
                       __FUNCTION__);
29
        }
30
 
31
        dbg_printf("New thread running successfully on cpu %d "
32
                   "tid=%d. Exiting...\n", self_tid(),
33
                   exregs.cpu_affinity);
34
#endif
35
 
36
        dbg_printf("SMP:New thread running successfully"
37
                   "tid=%d. Exiting...\n", self_tid());
38
 
39
        return 0;
40
}
41
 
42
/*
43
 * Create 2 threads on different cpus and run them.
44
 *
45
 * Parent then destroys the child. Parent and child
46
 * are on different cpus.
47
 */
48
int test_smp_two_threads(void)
49
{
50
        struct exregs_data exregs;
51
        struct l4_thread *thread;
52
        int err, err2;
53
 
54
        dbg_printf("%s: Creating a new thread\n", __FUNCTION__);
55
        /*
56
         * Create new thread but don't start it
57
         */
58
        if ((err = thread_create(new_thread_func, 0,
59
                                 TC_SHARE_SPACE | TC_NOSTART,
60
                                 &thread)) < 0) {
61
                dbg_printf("THREAD_CREATE failed. "
62
                           "err=%d\n", err);
63
                return err;
64
        }
65
#if 0
66
        dbg_printf("%s: Setting child affinity to %d\n", __FUNCTION__, 1);
67
        /*
68
         * Set its cpu affinity to cpu = 1
69
         */
70
        memset(&exregs, 0, sizeof(exregs));
71
        exregs_set_affinity(&exregs, 1);
72
 
73
        /* Write to affinity field */
74
        if ((err = l4_exchange_registers(&exregs,
75
                                         thread->ids.tid)) < 0) {
76
                printf("%s: Exregs on setting cpu affinity "
77
                       "failed on newly created thread. err=%d\n",
78
                       __FUNCTION__, err);
79
                goto out_err;
80
        }
81
 
82
        dbg_printf("%s: Running child on other cpu\n", __FUNCTION__);
83
#endif
84
        /* Start the thread */
85
        l4_thread_control(THREAD_RUN, &thread->ids);
86
 
87
        dbg_printf("%s: Waiting on child\n", __FUNCTION__);
88
        /* Wait on the thread */
89
        if ((err = thread_wait(thread)) < 0) {
90
                dbg_printf("THREAD_WAIT failed. "
91
                           "err=%d\n", err);
92
                goto out_err;
93
        } else {
94
                dbg_printf("Thread %d exited successfully. ret=%d\n",
95
                           thread->ids.tid, err);
96
        }
97
 
98
        dbg_printf("%s: Child destroyed successfully\n", __FUNCTION__);
99
        return 0;
100
 
101
out_err:
102
        /*
103
         * Destroy the thread from parent
104
         */
105
        if ((err2 = thread_destroy(thread)) < 0) {
106
                dbg_printf("THREAD_DESTROY failed. "
107
                           "err=%d\n", err2);
108
                return err2;
109
        }
110
        return err;
111
}
112
 
113
int test_smp_two_spaces(void)
114
{
115
        return 0;
116
}
117
 
118
int test_smp_ipc(void)
119
{
120
        return 0;
121
}
122
 
123
#if defined (CONFIG_SMP)
124
int test_smp(void)
125
{
126
        int err;
127
 
128
        if ((err = test_smp_two_threads()) < 0)
129
                return err;
130
 
131
        if ((err = test_smp_two_spaces()) < 0)
132
                return err;
133
 
134
        if ((err = test_smp_ipc()) < 0)
135
                return err;
136
 
137
        return 0;
138
}
139
#else /* Not CONFIG_SMP */
140
 
141
int test_smp(void)
142
{
143
        return 0;
144
}
145
#endif /* Endif */
146
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.