Subversion Repositories HelenOS

Rev

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

  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>
  31. #include <arch.h>
  32. #include <test.h>
  33. #include <proc/tasklet.h>
  34. #include <synch/waitq.h>
  35. #include <cpu.h>
  36. #include <proc/thread.h>
  37. #include <arch/types.h>
  38. #include <config.h>
  39.  
  40. bool gquiet;
  41. static void func(void *data)
  42. {
  43.     if (!gquiet)
  44.         printf("cpu%d: %s",CPU->id, data);
  45. }
  46.  
  47. #ifdef CONFIG_SMP
  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)
  57.         printf("cpu:%d, Registering tasklet...", CPU->id);
  58.     if (!gquiet)
  59.         tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
  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)
  67.         printf("cpu:%d, Disabling tasklet...", CPU->id);
  68.     tasklet_disable(tasklet_desc);
  69.     if (!gquiet)
  70.         printf("Done!\n");
  71.  
  72.     //we'll schedule the disabled tasklet
  73.     if (!gquiet)
  74.         printf("cpu:%d, Scheduling tasklet...", CPU->id);
  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)
  81.         printf("cpu:%d, Waiting 1s...\n", CPU->id);
  82.     waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
  83.     if (!gquiet)
  84.         printf("cpu:%d, Done!\n", CPU->id);
  85.  
  86.     //then we'll try to enable it
  87.     if (!gquiet)
  88.         printf("cpu:%d, Enabling tasklet...", CPU->id);
  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)
  95.         printf("cpu:%d, Waiting 1s...\n", CPU->id);
  96.     waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
  97.     if (!gquiet)
  98.         printf("cpu:%d, Done!\n", CPU->id);
  99.  
  100.     //finally we'll free the tasklet structure
  101.     if (!gquiet)
  102.         printf("cpu:%d, Freeing...", CPU->id);
  103.     tasklet_free(tasklet_desc);
  104.     if (!gquiet)
  105.         printf("Done!\n");
  106. }
  107. #endif
  108. char * test_tasklet1(bool quiet)
  109. {
  110.     gquiet = quiet;
  111.     waitq_t wq;
  112.     waitq_initialize(&wq);
  113.     tasklet_descriptor_t *tasklet_desc;
  114. #ifdef CONFIG_SMP
  115.     thread_t* second_thread = NULL;
  116.     if (!quiet)
  117.         printf("cpus:%d\n", config.cpu_active);
  118.  
  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
  128.  
  129.     //before we start we need to register a tasklet
  130.     if (!quiet)
  131.         printf("cpu:%d, Registering tasklet...", CPU->id);
  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)
  141.         printf("cpu:%d, Disabling tasklet...", CPU->id);
  142.     tasklet_disable(tasklet_desc);
  143.     if (!quiet)
  144.         printf("Done!\n");
  145.  
  146.     //we'll schedule the disabled tasklet
  147.     if (!quiet)
  148.         printf("cpu:%d, Scheduling tasklet...", CPU->id);
  149.     tasklet_schedule(tasklet_desc);
  150.     if (!quiet)
  151.         printf("Done!\n");
  152.  
  153.     //and we'll wait if it gets called. It shouldn't however, because it's disabled
  154.     if (!quiet)
  155.         printf("cpu:%d, Waiting 1s...\n", CPU->id);
  156.     waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
  157.     if (!quiet)
  158.         printf("cpu:%d, Done!\n", CPU->id);
  159.  
  160.  
  161.     //then we'll try to enable it
  162.     if (!quiet)
  163.         printf("cpu:%d, Enabling tasklet...", CPU->id);
  164.     tasklet_enable(tasklet_desc);
  165.     if (!quiet)
  166.         printf("Done!\n");
  167.    
  168.     //and wait if it gets called this time. It should because it's enabled
  169.     if (!quiet)
  170.         printf("cpu:%d, Waiting 1s...\n", CPU->id);
  171.     waitq_sleep_timeout(&wq,(uint32_t) 1000000,0);
  172.     if (!quiet)
  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.         }
  180.  
  181. #endif
  182.     //finally we'll free the tasklet structure
  183.     if (!quiet)
  184.         printf("cpu:%d, Freeing...", CPU->id);
  185.     tasklet_free(tasklet_desc);
  186.     if (!quiet)
  187.         printf("Done!\n");
  188.  
  189.  
  190.     return NULL;
  191. }
  192.