Re: l4/sys/syscalls.h: No such file or directory

Valentin Hauner <[email protected]>
Newsgroups gmane.comp.micro-kernel.l4.devel
Message-ID <[email protected]>
Hi,

thanks for your reply.

On 08/21/2014 11:49 PM, Adam Lackorzynski wrote:
> The main issue is that you start 2 threads and then immediately leave
> the main function, which exits your program and would also destroy all
> threads. But it does not get so far...
>   
> Each thread needs to have a unique UTCB. In this example, you could fix
> it like this:
>     l4re_env()->first_free_utcb = (l4_addr_t)l4re_env()->first_free_utcb + L4_UTCB_OFFSET;
> Remember that the size of the initial UTCB area is limited, so this only
> works  a few times (allocating more is possible).
>
> As both threads use the same UTCB this could result in the behavior
> you're seeing.
>   
I've tried both of your suggestions, but none of them solved the problem.
Then I've added
> l4re_util_cap_free_um(thread_caps[x]);
at the end of each thread function and now the exception does not appear
any more. All output ("Hello World ...") is produced as supposed to be.

I've attached the modified source file for your convenience. Note that
the idling of the main thread (lines 109 f.) as well as the manipulation
of first_free_utcb (line 99) are _commented out_.

Obviously, both created threads can go on although the main thread has
already ended? Why?
Is it right that the manipulation of first_free_utcb is necessary only
when there is any IPC? In my example, none of the threads is
communicating via the message registers.

Best regards,
Valentin

_______________________________________________
l4-hackers mailing list
[email protected]
http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
main.c (text/x-csrc, 2.8 KB)
/**
 * \file
 * \brief Example of creating threads for the EDF scheduler
 *
 * This example shows how threads owning a deadline are created for the EDF scheduler.
 * It's adapted from the utcb-ipc example by Adam Lackorzynski, Alexander Warg and Björn Döbel.
 */
/* 
 *
 * (c) 2014 Valentin Hauner <[email protected]>
 *
 * This file is distributed under the terms of the
 * GNU General Public License 2.
 * Please see the COPYING-GPL-2 file for details.
 */
#include <l4/sys/ipc.h>
#include <l4/sys/thread.h>

#include <l4/sys/factory.h>
#include <l4/sys/utcb.h>
#include <l4/re/env.h>
#include <l4/re/c/util/cap_alloc.h>

#include "l4/sys/kdebug.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"
#define ANSI_COLOR_RESET   "\x1b[0m"

static unsigned char *thread_stacks[20];
static l4_cap_idx_t   thread_caps[20];
static unsigned       count = 0;

static void thread1(void)
{
  int i;
  for (i = 0; i < 10; i++)
  {
    printf(ANSI_COLOR_BLUE "Thread 1: Hello World %d!" ANSI_COLOR_RESET "\n", i);
  }

  l4re_util_cap_free_um(thread_caps[0]);
}

static void thread2(void)
{
  int j;
  for (j = 0; j < 10; j++)
  {
    printf(ANSI_COLOR_GREEN "Thread 2: Hello World %d!" ANSI_COLOR_RESET "\n", j);
  }

  l4re_util_cap_free_um(thread_caps[1]);
}

static int create_edf_thread(void *func, unsigned deadline) {
  thread_stacks[count] = malloc(8 << 10);

  l4_msgtag_t tag;
  l4_cap_idx_t thread_cap = l4re_util_cap_alloc();

  if (l4_is_invalid_cap(thread_cap))
    return -1;

  tag = l4_factory_create_thread(l4re_env()->factory, thread_cap);
  if (l4_error(tag))
    return -1;

  l4_thread_control_start();
  l4_thread_control_pager(l4re_env()->rm);
  l4_thread_control_exc_handler(l4re_env()->rm);
  l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb,
                          L4RE_THIS_TASK_CAP);
  tag = l4_thread_control_commit(thread_cap);
  if (l4_error(tag))
    return -2;

  tag = l4_thread_ex_regs(thread_cap,
                          (l4_umword_t)func,
                          (l4_umword_t)(thread_stacks[count] + sizeof(thread_stacks[count])), 0);
  if (l4_error(tag))
    return -3;

  l4_sched_param_t sp = l4_sched_param_by_type(Deadline, deadline, 0);
  tag = l4_scheduler_run_thread(l4re_env()->scheduler, thread_cap, &sp);
  if (l4_error(tag))
    return -4;

  thread_caps[count] = thread_cap;

  //l4re_env()->first_free_utcb = (l4_addr_t)l4re_env()->first_free_utcb + L4_UTCB_OFFSET;

  return count++;
}

int main(void)
{
  create_edf_thread(thread1, 1);
  create_edf_thread(thread2, 3);

  // Idle around...
  /*
  while (1)
    sleep(1);
  */
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.