Subversion Repositories HelenOS

Rev

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

Rev 2265 Rev 2283
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
 
-
 
-
 
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
 
-
 
-
 
35
#include <cpu.h>
-
 
36
#include <proc/thread.h>
36
#include <arch/types.h>
37
#include <arch/types.h>
-
 
38
#include <config.h>
37
 
39
 
38
static void func(void *data)
40
static void func(void *data)
39
{
41
{
-
 
42
    printf("cpu%d: %s",CPU->id, data);
-
 
43
}
-
 
44
 
-
 
45
bool gquiet;
-
 
46
 
-
 
47
static void running_tasklet(void * data)
-
 
48
{
-
 
49
    waitq_t wq;
-
 
50
    waitq_initialize(&wq);
-
 
51
 
-
 
52
    tasklet_descriptor_t *tasklet_desc;
-
 
53
    //before we start we need to register a tasklet
-
 
54
    if (!gquiet)
-
 
55
        printf("Registering tasklet...");
-
 
56
    if (!gquiet)
-
 
57
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data from second thread\n");
-
 
58
    else
-
 
59
        tasklet_desc=tasklet_register(&func, "");
-
 
60
    if (!gquiet)
-
 
61
        printf("Done!\n");
-
 
62
 
-
 
63
    //first we'll try disabling the tasklet
-
 
64
    if (!gquiet)
-
 
65
        printf("Disabling tasklet...");
-
 
66
    tasklet_disable(tasklet_desc);
-
 
67
    if (!gquiet)
-
 
68
        printf("Done!\n");
-
 
69
 
-
 
70
    //we'll schedule the disabled tasklet
-
 
71
    if (!gquiet)
-
 
72
        printf("Scheduling tasklet...");
-
 
73
    tasklet_schedule(tasklet_desc);
-
 
74
    if (!gquiet)
-
 
75
        printf("Done!\n");
-
 
76
 
-
 
77
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
-
 
78
    if (!gquiet)
-
 
79
        printf("Waiting 1s...\n");
-
 
80
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
-
 
81
    if (!gquiet)
-
 
82
        printf("Done!\n");
-
 
83
 
-
 
84
    //then we'll try to enable it
-
 
85
    if (!gquiet)
-
 
86
        printf("Enabling tasklet...");
-
 
87
    tasklet_enable(tasklet_desc);
-
 
88
    if (!gquiet)
-
 
89
        printf("Done!\n");
-
 
90
   
-
 
91
    //and wait if it gets called this time. It should because it's enabled
-
 
92
    if (!gquiet)
-
 
93
        printf("Waiting 1s...\n");
-
 
94
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
-
 
95
    if (!gquiet)
-
 
96
        printf("Done!\n");
-
 
97
 
-
 
98
    //finally we'll free the tasklet structure
-
 
99
    if (!gquiet)
-
 
100
        printf("Freeing...");
-
 
101
    tasklet_free(tasklet_desc);
-
 
102
    if (!gquiet)
40
    printf("%s", data);
103
        printf("Done!\n");
41
}
104
}
42
 
105
 
43
char * test_tasklet1(bool quiet)
106
char * test_tasklet1(bool quiet)
44
{
107
{
-
 
108
    gquiet = quiet;
45
    waitq_t wq;
109
    waitq_t wq;
46
    waitq_initialize(&wq);
110
    waitq_initialize(&wq);
47
    tasklet_descriptor_t *tasklet_desc;
111
    tasklet_descriptor_t *tasklet_desc;
-
 
112
    thread_t* second_thread;
-
 
113
#ifdef CONFIG_SMP
-
 
114
    if (config.cpu_active >1) {
-
 
115
        second_thread = thread_create(&running_tasklet, NULL, TASK, THREAD_FLAG_WIRED,"running tasklet", false);
-
 
116
        if (CPU->id == 0)
-
 
117
            second_thread->cpu = &cpus[1];
-
 
118
        else
-
 
119
            second_thread->cpu = &cpus[0];
-
 
120
        thread_ready(second_thread);
-
 
121
    }
-
 
122
#endif
48
 
123
 
49
    //before we start we need to register a tasklet
124
    //before we start we need to register a tasklet
50
    if (!quiet)
125
    if (!quiet)
51
        printf("Registering tasklet...");
126
        printf("Registering tasklet...");
52
    if (!quiet)
127
    if (!quiet)
53
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
128
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
54
    else
129
    else
55
        tasklet_desc=tasklet_register(&func, "");
130
        tasklet_desc=tasklet_register(&func, "");
56
    if (!quiet)
131
    if (!quiet)
57
        printf("Done!\n");
132
        printf("Done!\n");
58
 
133
 
59
    //first we'll try disabling the tasklet
134
    //first we'll try disabling the tasklet
60
    if (!quiet)
135
    if (!quiet)
61
        printf("Disabling tasklet...");
136
        printf("Disabling tasklet...");
62
    tasklet_disable(tasklet_desc);
137
    tasklet_disable(tasklet_desc);
63
    if (!quiet)
138
    if (!quiet)
64
        printf("Done!\n");
139
        printf("Done!\n");
65
 
140
 
66
    //we'll schedule the disabled tasklet
141
    //we'll schedule the disabled tasklet
67
    if (!quiet)
142
    if (!quiet)
68
        printf("Scheduling tasklet...");
143
        printf("Scheduling tasklet...");
69
    tasklet_schedule(tasklet_desc);
144
    tasklet_schedule(tasklet_desc);
70
    if (!quiet)
145
    if (!quiet)
71
        printf("Done!\n");
146
        printf("Done!\n");
72
 
147
 
73
    //and we'll wait if it gets called. It shouldn't however because it's disabled
148
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
74
    if (!quiet)
149
    if (!quiet)
75
        printf("Waiting 5s...");
150
        printf("Waiting 1s...\n");
76
    waitq_sleep_timeout(&wq,(uint32_t) 5000000,0);
151
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
77
    if (!quiet)
152
    if (!quiet)
78
        printf("Done!\n");
153
        printf("Done!\n");
79
 
154
 
80
    //then we'll try to enable it
155
    //then we'll try to enable it
81
    if (!quiet)
156
    if (!quiet)
82
        printf("Enabling tasklet...");
157
        printf("Enabling tasklet...");
83
    tasklet_enable(tasklet_desc);
158
    tasklet_enable(tasklet_desc);
84
    if (!quiet)
159
    if (!quiet)
85
        printf("Done!\n");
160
        printf("Done!\n");
86
   
161
   
87
    //and wait if it gets called this time. It should beacause it's enabled
162
    //and wait if it gets called this time. It should because it's enabled
88
    if (!quiet)
163
    if (!quiet)
89
        printf("Waiting 5s...");
164
        printf("Waiting 1s...\n");
90
    waitq_sleep_timeout(&wq,(uint32_t) 5000000,0);
165
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
91
    if (!quiet)
166
    if (!quiet)
92
        printf("Done!\n");
167
        printf("Done!\n");
93
 
168
 
94
    //finally we'll free the tasklet structure
169
    //finally we'll free the tasklet structure
95
    if (!quiet)
170
    if (!quiet)
96
        printf("Freeing...");
171
        printf("Freeing...");
97
    tasklet_free(tasklet_desc);
172
    tasklet_free(tasklet_desc);
98
    if (!quiet)
173
    if (!quiet)
99
        printf("Done!\n");
174
        printf("Done!\n");
100
 
175
 
101
 
176
 
102
    return NULL;
177
    return NULL;
103
}
178
}
104
 
179