Subversion Repositories HelenOS

Rev

Rev 2283 | Rev 2307 | Go to most recent revision | 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
 
40
static void func(void *data)
41
{
2283 hudecek 42
    printf("cpu%d: %s",CPU->id, data);
2260 hudecek 43
}
44
 
2283 hudecek 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)
2292 hudecek 55
        printf("cpu:%d, Registering tasklet...", CPU->id);
2283 hudecek 56
    if (!gquiet)
2292 hudecek 57
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
2283 hudecek 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)
2292 hudecek 65
        printf("cpu:%d, Disabling tasklet...", CPU->id);
2283 hudecek 66
    tasklet_disable(tasklet_desc);
67
    if (!gquiet)
68
        printf("Done!\n");
69
 
70
    //we'll schedule the disabled tasklet
71
    if (!gquiet)
2292 hudecek 72
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
2283 hudecek 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)
2292 hudecek 79
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
2283 hudecek 80
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
81
    if (!gquiet)
2292 hudecek 82
        printf("cpu:%d, Done!\n", CPU->id);
2283 hudecek 83
 
84
    //then we'll try to enable it
85
    if (!gquiet)
2292 hudecek 86
        printf("cpu:%d, Enabling tasklet...", CPU->id);
2283 hudecek 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)
2292 hudecek 93
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
2283 hudecek 94
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
95
    if (!gquiet)
2292 hudecek 96
        printf("cpu:%d, Done!\n", CPU->id);
2283 hudecek 97
 
98
    //finally we'll free the tasklet structure
99
    if (!gquiet)
2292 hudecek 100
        printf("cpu:%d, Freeing...", CPU->id);
2283 hudecek 101
    tasklet_free(tasklet_desc);
102
    if (!gquiet)
103
        printf("Done!\n");
104
}
105
 
2260 hudecek 106
char * test_tasklet1(bool quiet)
107
{
2283 hudecek 108
    gquiet = quiet;
2260 hudecek 109
    waitq_t wq;
110
    waitq_initialize(&wq);
111
    tasklet_descriptor_t *tasklet_desc;
2292 hudecek 112
    thread_t* second_thread = NULL;
2283 hudecek 113
#ifdef CONFIG_SMP
2292 hudecek 114
    if (!quiet)
115
        printf("cpus:%d\n", config.cpu_active);
116
 
2283 hudecek 117
    if (config.cpu_active >1) {
118
        second_thread = thread_create(&running_tasklet, NULL, TASK, THREAD_FLAG_WIRED,"running tasklet", false);
119
        if (CPU->id == 0)
120
            second_thread->cpu = &cpus[1];
121
        else
122
            second_thread->cpu = &cpus[0];
123
        thread_ready(second_thread);
124
    }
125
#endif
2260 hudecek 126
 
127
    //before we start we need to register a tasklet
128
    if (!quiet)
2292 hudecek 129
        printf("cpu:%d, Registering tasklet...", CPU->id);
2260 hudecek 130
    if (!quiet)
131
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
132
    else
133
        tasklet_desc=tasklet_register(&func, "");
134
    if (!quiet)
135
        printf("Done!\n");
136
 
137
    //first we'll try disabling the tasklet
138
    if (!quiet)
2292 hudecek 139
        printf("cpu:%d, Disabling tasklet...", CPU->id);
2260 hudecek 140
    tasklet_disable(tasklet_desc);
141
    if (!quiet)
142
        printf("Done!\n");
143
 
144
    //we'll schedule the disabled tasklet
145
    if (!quiet)
2292 hudecek 146
        printf("cpu:%d, Scheduling tasklet...", CPU->id);
2260 hudecek 147
    tasklet_schedule(tasklet_desc);
148
    if (!quiet)
149
        printf("Done!\n");
150
 
2283 hudecek 151
    //and we'll wait if it gets called. It shouldn't however, because it's disabled
2260 hudecek 152
    if (!quiet)
2292 hudecek 153
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
2283 hudecek 154
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
2260 hudecek 155
    if (!quiet)
2292 hudecek 156
        printf("cpu:%d, Done!\n", CPU->id);
2260 hudecek 157
 
2292 hudecek 158
 
2260 hudecek 159
    //then we'll try to enable it
160
    if (!quiet)
2292 hudecek 161
        printf("cpu:%d, Enabling tasklet...", CPU->id);
2260 hudecek 162
    tasklet_enable(tasklet_desc);
163
    if (!quiet)
164
        printf("Done!\n");
165
 
2283 hudecek 166
    //and wait if it gets called this time. It should because it's enabled
2260 hudecek 167
    if (!quiet)
2292 hudecek 168
        printf("cpu:%d, Waiting 1s...\n", CPU->id);
2283 hudecek 169
    waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
2260 hudecek 170
    if (!quiet)
2292 hudecek 171
        printf("cpu:%d, Done!\n", CPU->id);
172
#ifdef CONFIG_SMP
173
        if (config.cpu_active >1) {
174
            printf("Joining with the second thread...");
175
            thread_join(second_thread);
176
            printf("Done\n");
177
        }
2260 hudecek 178
 
2292 hudecek 179
#endif
2260 hudecek 180
    //finally we'll free the tasklet structure
181
    if (!quiet)
2292 hudecek 182
        printf("cpu:%d, Freeing...", CPU->id);
2260 hudecek 183
    tasklet_free(tasklet_desc);
184
    if (!quiet)
185
        printf("Done!\n");
186
 
187
 
188
    return NULL;
189
}