Subversion Repositories HelenOS

Rev

Rev 2307 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2307 Rev 2456
1
/*
1
/*
2
 * Copyright (c) 2007 Jan Hudecek
2
 * Copyright (c) 2007 Jan Hudecek
3
 * Copyright (c) 2005 Jakub Jermar
3
 * Copyright (c) 2005 Jakub Jermar
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#include <print.h>
30
#include <print.h>
31
#include <arch.h>
31
#include <arch.h>
32
#include <test.h>
32
#include <test.h>
33
#include <proc/tasklet.h>
33
#include <proc/tasklet.h>
34
#include <synch/waitq.h>
34
#include <synch/waitq.h>
35
#include <cpu.h>
35
#include <cpu.h>
36
#include <proc/thread.h>
36
#include <proc/thread.h>
37
#include <arch/types.h>
37
#include <arch/types.h>
38
#include <config.h>
38
#include <config.h>
39
 
39
 
-
 
40
bool gquiet;
40
static void func(void *data)
41
static void func(void *data)
41
{
42
{
-
 
43
    if (!gquiet)
42
    printf("cpu%d: %s",CPU->id, data);
44
        printf("cpu%d: %s",CPU->id, data);
43
}
45
}
44
 
46
 
45
bool gquiet;
-
 
46
#ifdef CONFIG_SMP
47
#ifdef CONFIG_SMP
47
 
48
 
48
static void running_tasklet(void * data)
49
static void running_tasklet(void * data)
49
{
50
{
50
    waitq_t wq;
51
    waitq_t wq;
51
    waitq_initialize(&wq);
52
    waitq_initialize(&wq);
52
 
53
 
53
    tasklet_descriptor_t *tasklet_desc;
54
    tasklet_descriptor_t *tasklet_desc;
54
    //before we start we need to register a tasklet
55
    //before we start we need to register a tasklet
55
    if (!gquiet)
56
    if (!gquiet)
56
        printf("cpu:%d, Registering tasklet...", CPU->id);
57
        printf("cpu:%d, Registering tasklet...", CPU->id);
57
    if (!gquiet)
58
    if (!gquiet)
58
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
59
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
59
    else
60
    else
60
        tasklet_desc=tasklet_register(&func, "");
61
        tasklet_desc=tasklet_register(&func, "");
61
    if (!gquiet)
62
    if (!gquiet)
62
        printf("Done!\n");
63
        printf("Done!\n");
63
 
64
 
64
    //first we'll try disabling the tasklet
65
    //first we'll try disabling the tasklet
65
    if (!gquiet)
66
    if (!gquiet)
66
        printf("cpu:%d, Disabling tasklet...", CPU->id);
67
        printf("cpu:%d, Disabling tasklet...", CPU->id);
67
    tasklet_disable(tasklet_desc);
68
    tasklet_disable(tasklet_desc);
68
    if (!gquiet)
69
    if (!gquiet)
69
        printf("Done!\n");
70
        printf("Done!\n");
70
 
71
 
71
    //we'll schedule the disabled tasklet
72
    //we'll schedule the disabled tasklet
72
    if (!gquiet)
73
    if (!gquiet)
73
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
74
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
74
    tasklet_schedule(tasklet_desc);
75
    tasklet_schedule(tasklet_desc);
75
    if (!gquiet)
76
    if (!gquiet)
76
        printf("Done!\n");
77
        printf("Done!\n");
77
 
78
 
78
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
79
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
79
    if (!gquiet)
80
    if (!gquiet)
80
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
81
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
81
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
82
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
82
    if (!gquiet)
83
    if (!gquiet)
83
        printf("cpu:%d, Done!\n", CPU->id);
84
        printf("cpu:%d, Done!\n", CPU->id);
84
 
85
 
85
    //then we'll try to enable it
86
    //then we'll try to enable it
86
    if (!gquiet)
87
    if (!gquiet)
87
        printf("cpu:%d, Enabling tasklet...", CPU->id);
88
        printf("cpu:%d, Enabling tasklet...", CPU->id);
88
    tasklet_enable(tasklet_desc);
89
    tasklet_enable(tasklet_desc);
89
    if (!gquiet)
90
    if (!gquiet)
90
        printf("Done!\n");
91
        printf("Done!\n");
91
   
92
   
92
    //and wait if it gets called this time. It should because it's enabled
93
    //and wait if it gets called this time. It should because it's enabled
93
    if (!gquiet)
94
    if (!gquiet)
94
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
95
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
95
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
96
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
96
    if (!gquiet)
97
    if (!gquiet)
97
        printf("cpu:%d, Done!\n", CPU->id);
98
        printf("cpu:%d, Done!\n", CPU->id);
98
 
99
 
99
    //finally we'll free the tasklet structure
100
    //finally we'll free the tasklet structure
100
    if (!gquiet)
101
    if (!gquiet)
101
        printf("cpu:%d, Freeing...", CPU->id);
102
        printf("cpu:%d, Freeing...", CPU->id);
102
    tasklet_free(tasklet_desc);
103
    tasklet_free(tasklet_desc);
103
    if (!gquiet)
104
    if (!gquiet)
104
        printf("Done!\n");
105
        printf("Done!\n");
105
}
106
}
106
#endif
107
#endif
107
char * test_tasklet1(bool quiet)
108
char * test_tasklet1(bool quiet)
108
{
109
{
109
    gquiet = quiet;
110
    gquiet = quiet;
110
    waitq_t wq;
111
    waitq_t wq;
111
    waitq_initialize(&wq);
112
    waitq_initialize(&wq);
112
    tasklet_descriptor_t *tasklet_desc;
113
    tasklet_descriptor_t *tasklet_desc;
113
#ifdef CONFIG_SMP
114
#ifdef CONFIG_SMP
114
    thread_t* second_thread = NULL;
115
    thread_t* second_thread = NULL;
115
    if (!quiet)
116
    if (!quiet)
116
        printf("cpus:%d\n", config.cpu_active);
117
        printf("cpus:%d\n", config.cpu_active);
117
 
118
 
118
    if (config.cpu_active >1) {
119
    if (config.cpu_active >1) {
119
        second_thread = thread_create(&running_tasklet, NULL, TASK, THREAD_FLAG_WIRED,"running tasklet", false);
120
        second_thread = thread_create(&running_tasklet, NULL, TASK, THREAD_FLAG_WIRED,"running tasklet", false);
120
        if (CPU->id == 0)
121
        if (CPU->id == 0)
121
            second_thread->cpu = &cpus[1];
122
            second_thread->cpu = &cpus[1];
122
        else
123
        else
123
            second_thread->cpu = &cpus[0];
124
            second_thread->cpu = &cpus[0];
124
        thread_ready(second_thread);
125
        thread_ready(second_thread);
125
    }
126
    }
126
#endif
127
#endif
127
 
128
 
128
    //before we start we need to register a tasklet
129
    //before we start we need to register a tasklet
129
    if (!quiet)
130
    if (!quiet)
130
        printf("cpu:%d, Registering tasklet...", CPU->id);
131
        printf("cpu:%d, Registering tasklet...", CPU->id);
131
    if (!quiet)
132
    if (!quiet)
132
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
133
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
133
    else
134
    else
134
        tasklet_desc=tasklet_register(&func, "");
135
        tasklet_desc=tasklet_register(&func, "");
135
    if (!quiet)
136
    if (!quiet)
136
        printf("Done!\n");
137
        printf("Done!\n");
137
 
138
 
138
    //first we'll try disabling the tasklet
139
    //first we'll try disabling the tasklet
139
    if (!quiet)
140
    if (!quiet)
140
        printf("cpu:%d, Disabling tasklet...", CPU->id);
141
        printf("cpu:%d, Disabling tasklet...", CPU->id);
141
    tasklet_disable(tasklet_desc);
142
    tasklet_disable(tasklet_desc);
142
    if (!quiet)
143
    if (!quiet)
143
        printf("Done!\n");
144
        printf("Done!\n");
144
 
145
 
145
    //we'll schedule the disabled tasklet
146
    //we'll schedule the disabled tasklet
146
    if (!quiet)
147
    if (!quiet)
147
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
148
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
148
    tasklet_schedule(tasklet_desc);
149
    tasklet_schedule(tasklet_desc);
149
    if (!quiet)
150
    if (!quiet)
150
        printf("Done!\n");
151
        printf("Done!\n");
151
 
152
 
152
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
153
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
153
    if (!quiet)
154
    if (!quiet)
154
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
155
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
155
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
156
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
156
    if (!quiet)
157
    if (!quiet)
157
        printf("cpu:%d, Done!\n", CPU->id);
158
        printf("cpu:%d, Done!\n", CPU->id);
158
 
159
 
159
 
160
 
160
    //then we'll try to enable it
161
    //then we'll try to enable it
161
    if (!quiet)
162
    if (!quiet)
162
        printf("cpu:%d, Enabling tasklet...", CPU->id);
163
        printf("cpu:%d, Enabling tasklet...", CPU->id);
163
    tasklet_enable(tasklet_desc);
164
    tasklet_enable(tasklet_desc);
164
    if (!quiet)
165
    if (!quiet)
165
        printf("Done!\n");
166
        printf("Done!\n");
166
   
167
   
167
    //and wait if it gets called this time. It should because it's enabled
168
    //and wait if it gets called this time. It should because it's enabled
168
    if (!quiet)
169
    if (!quiet)
169
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
170
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
170
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
171
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
171
    if (!quiet)
172
    if (!quiet)
172
        printf("cpu:%d, Done!\n", CPU->id);
173
        printf("cpu:%d, Done!\n", CPU->id);
173
#ifdef CONFIG_SMP
174
#ifdef CONFIG_SMP
174
        if (config.cpu_active >1) {
175
        if (config.cpu_active >1) {
175
            printf("Joining with the second thread...");
176
            printf("Joining with the second thread...");
176
            thread_join(second_thread);
177
            thread_join(second_thread);
177
            printf("Done\n");
178
            printf("Done\n");
178
        }
179
        }
179
 
180
 
180
#endif
181
#endif
181
    //finally we'll free the tasklet structure
182
    //finally we'll free the tasklet structure
182
    if (!quiet)
183
    if (!quiet)
183
        printf("cpu:%d, Freeing...", CPU->id);
184
        printf("cpu:%d, Freeing...", CPU->id);
184
    tasklet_free(tasklet_desc);
185
    tasklet_free(tasklet_desc);
185
    if (!quiet)
186
    if (!quiet)
186
        printf("Done!\n");
187
        printf("Done!\n");
187
 
188
 
188
 
189
 
189
    return NULL;
190
    return NULL;
190
}
191
}
191
 
192