Subversion Repositories HelenOS

Rev

Rev 2307 | Details | Compare with Previous | Last modification | View Log | RSS feed

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