2013-12-02 10:24:35 +01:00
|
|
|
/*
|
2014-01-10 17:32:20 +01:00
|
|
|
* \brief Testing thread library
|
2013-12-02 10:24:35 +01:00
|
|
|
* \author Alexander Boettcher
|
2014-01-10 17:32:20 +01:00
|
|
|
* \author Christian Helmuth
|
2013-12-02 10:24:35 +01:00
|
|
|
* \date 2013-12-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-12-02 10:24:35 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-12-02 10:24:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
2019-11-19 16:28:33 +01:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
2016-05-04 12:27:17 +02:00
|
|
|
#include <base/component.h>
|
|
|
|
#include <base/heap.h>
|
2019-11-19 16:28:33 +01:00
|
|
|
#include <base/log.h>
|
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <base/rpc_client.h>
|
|
|
|
#include <base/thread.h>
|
2016-12-01 17:37:08 +01:00
|
|
|
#include <util/reconstructible.h>
|
2014-04-03 14:18:52 +02:00
|
|
|
#include <cpu_session/connection.h>
|
2016-05-10 18:05:38 +02:00
|
|
|
#include <cpu_thread/client.h>
|
2017-06-16 16:27:56 +02:00
|
|
|
#include <cpu/memory_barrier.h>
|
2013-12-02 10:24:35 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2014-01-10 17:32:20 +01:00
|
|
|
|
2019-09-03 12:07:10 +02:00
|
|
|
enum { STACK_SIZE = 0x3000 };
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/*********************************
|
|
|
|
** Stack-allocator concurrency **
|
|
|
|
*********************************/
|
2014-02-05 17:05:32 +01:00
|
|
|
|
2014-01-10 17:32:20 +01:00
|
|
|
template <int CHILDREN>
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
class Helper : Thread
|
2014-01-10 17:32:20 +01:00
|
|
|
{
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
private:
|
2014-01-10 17:32:20 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Helper(Helper const &);
|
|
|
|
Helper &operator = (Helper const &);
|
2016-05-04 12:27:17 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
public:
|
2016-05-04 12:27:17 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
using Thread::start;
|
|
|
|
using Thread::join;
|
2014-01-10 17:32:20 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
void *child[CHILDREN];
|
2014-01-10 17:32:20 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Env &_env;
|
2016-05-04 12:27:17 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Helper(Env &env) : Thread(env, "helper", STACK_SIZE), _env(env) { }
|
|
|
|
|
|
|
|
void *stack() const { return _stack; }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
{
|
|
|
|
Constructible<Helper> helper[CHILDREN];
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < CHILDREN; ++i)
|
|
|
|
helper[i].construct(_env);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < CHILDREN; ++i)
|
|
|
|
child[i] = helper[i]->stack();
|
|
|
|
}
|
2014-01-10 17:32:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
static void test_stack_alloc(Env &env)
|
2014-01-10 17:32:20 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2014-01-10 17:32:20 +01:00
|
|
|
/*
|
|
|
|
* Create HELPER threads, which concurrently create CHILDREN threads each.
|
2016-01-23 14:42:55 +01:00
|
|
|
* This most likely triggers any race in the stack allocation.
|
2014-01-10 17:32:20 +01:00
|
|
|
*/
|
2014-04-29 10:57:39 +02:00
|
|
|
enum { HELPER = 10, CHILDREN = 9 };
|
2014-01-10 17:32:20 +01:00
|
|
|
|
2016-12-01 17:37:08 +01:00
|
|
|
Constructible<Helper<CHILDREN> > helper[HELPER];
|
2014-01-10 17:32:20 +01:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
for (unsigned i = 0; i < HELPER; ++i) helper[i].construct(env);
|
|
|
|
for (unsigned i = 0; i < HELPER; ++i) helper[i]->start();
|
|
|
|
for (unsigned i = 0; i < HELPER; ++i) helper[i]->join();
|
2014-01-10 17:32:20 +01:00
|
|
|
|
|
|
|
if (0)
|
|
|
|
for (unsigned i = 0; i < HELPER; ++i)
|
|
|
|
for (unsigned j = 0; j < CHILDREN; ++j)
|
2016-05-04 12:27:17 +02:00
|
|
|
log(helper[i]->child[j], " [", i, ".", j, "]");
|
2014-01-10 17:32:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-05 17:05:32 +01:00
|
|
|
/*********************
|
|
|
|
** Stack alignment **
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Aligned FPU instruction accesses are very useful to identify stack-alignment
|
|
|
|
* issues. Fortunately, GCC generates pushes of FPU register content for
|
|
|
|
* vararg functions if floating-point values are passed to the function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void test_stack_alignment_varargs(char const *format, ...) __attribute__((noinline));
|
|
|
|
static void test_stack_alignment_varargs(char const *format, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, format);
|
2016-10-10 16:22:43 +02:00
|
|
|
log(va_arg(list, double));
|
|
|
|
log(va_arg(list, double));
|
2014-02-05 17:05:32 +01:00
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void log_stack_address(char const *who)
|
|
|
|
{
|
|
|
|
long dummy;
|
2016-05-04 12:27:17 +02:00
|
|
|
log(who, " stack @ ", &dummy);
|
2014-02-05 17:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
struct Stack_helper : Thread
|
2014-02-05 17:05:32 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
Stack_helper(Env &env) : Thread(env, "stack_helper", STACK_SIZE) { }
|
2014-02-05 17:05:32 +01:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2014-02-05 17:05:32 +01:00
|
|
|
{
|
|
|
|
log_stack_address("helper");
|
|
|
|
test_stack_alignment_varargs("%f\n%g\n", 3.142, 2.718);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
static void test_stack_alignment(Env &env)
|
2014-02-05 17:05:32 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Stack_helper helper(env);
|
2014-02-05 17:05:32 +01:00
|
|
|
|
|
|
|
helper.start();
|
|
|
|
helper.join();
|
|
|
|
|
|
|
|
log_stack_address("main");
|
|
|
|
test_stack_alignment_varargs("%f\n%g\n", 3.142, 2.718);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************
|
|
|
|
** Main-thread stack area **
|
|
|
|
****************************/
|
|
|
|
|
2014-01-10 17:32:20 +01:00
|
|
|
static void test_main_thread()
|
2013-12-02 10:24:35 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2013-12-02 10:24:35 +01:00
|
|
|
/* check wether my thread object exists */
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread * myself = Thread::myself();
|
2014-01-10 17:32:20 +01:00
|
|
|
if (!myself) { throw -1; }
|
2016-05-04 12:27:17 +02:00
|
|
|
log("thread base ", myself);
|
2013-12-02 10:24:35 +01:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* check whether my stack is inside the first stack region */
|
2016-05-04 12:27:17 +02:00
|
|
|
addr_t const stack_slot_base = Thread::stack_area_virtual_base();
|
|
|
|
addr_t const stack_slot_size = Thread::stack_area_virtual_size();
|
2016-01-23 14:42:55 +01:00
|
|
|
addr_t const stack_slot_top = stack_slot_base + stack_slot_size;
|
|
|
|
|
2013-12-02 10:24:35 +01:00
|
|
|
addr_t const stack_top = (addr_t)myself->stack_top();
|
|
|
|
addr_t const stack_base = (addr_t)myself->stack_base();
|
2016-01-23 14:42:55 +01:00
|
|
|
|
|
|
|
if (stack_top <= stack_slot_base) { throw -2; }
|
|
|
|
if (stack_top > stack_slot_top) { throw -3; }
|
|
|
|
if (stack_base >= stack_slot_top) { throw -4; }
|
|
|
|
if (stack_base < stack_slot_base) { throw -5; }
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
log("thread stack top ", myself->stack_top());
|
|
|
|
log("thread stack bottom ", myself->stack_base());
|
2013-12-02 10:24:35 +01:00
|
|
|
|
|
|
|
/* check wether my stack pointer is inside my stack */
|
|
|
|
unsigned dummy = 0;
|
|
|
|
addr_t const sp = (addr_t)&dummy;
|
2014-01-10 17:32:20 +01:00
|
|
|
if (sp >= stack_top) { throw -6; }
|
|
|
|
if (sp < stack_base) { throw -7; }
|
2016-05-04 12:27:17 +02:00
|
|
|
log("thread stack pointer ", (void *)sp);
|
2014-01-10 17:32:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 14:18:52 +02:00
|
|
|
/******************************************
|
|
|
|
** Using cpu-session for thread creation *
|
|
|
|
******************************************/
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
struct Cpu_helper : Thread
|
2014-04-03 14:18:52 +02:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
Env &_env;
|
|
|
|
|
|
|
|
Cpu_helper(Env &env, const char * name, Cpu_session &cpu)
|
|
|
|
:
|
|
|
|
Thread(env, name, STACK_SIZE, Thread::Location(), Thread::Weight(), cpu),
|
|
|
|
_env(env)
|
|
|
|
{ }
|
2014-04-03 14:18:52 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2014-04-03 14:18:52 +02:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log(Thread::name().string(), " : _cpu_session=", _cpu_session,
|
|
|
|
" env.cpu()=", &_env.cpu());
|
2014-04-03 14:18:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-29 10:57:39 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
static void test_cpu_session(Env &env)
|
2014-04-03 14:18:52 +02:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Cpu_helper thread0(env, "prio high ", env.cpu());
|
2014-04-03 14:18:52 +02:00
|
|
|
thread0.start();
|
|
|
|
thread0.join();
|
|
|
|
|
2017-03-01 21:52:00 +01:00
|
|
|
Cpu_connection con1(env, "prio middle", Cpu_session::PRIORITY_LIMIT / 4);
|
2016-05-04 12:27:17 +02:00
|
|
|
Cpu_helper thread1(env, "prio middle", con1);
|
2014-04-03 14:18:52 +02:00
|
|
|
thread1.start();
|
|
|
|
thread1.join();
|
|
|
|
|
2017-03-01 21:52:00 +01:00
|
|
|
Cpu_connection con2(env, "prio low", Cpu_session::PRIORITY_LIMIT / 2);
|
2016-05-04 12:27:17 +02:00
|
|
|
Cpu_helper thread2(env, "prio low ", con2);
|
2014-04-03 14:18:52 +02:00
|
|
|
thread2.start();
|
|
|
|
thread2.join();
|
|
|
|
}
|
|
|
|
|
2014-04-29 10:57:39 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
struct Pause_helper : Thread
|
2014-09-05 17:00:31 +02:00
|
|
|
{
|
|
|
|
volatile unsigned loop = 0;
|
|
|
|
volatile bool beep = false;
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Pause_helper(Env &env, const char * name, Cpu_session &cpu)
|
|
|
|
: Thread(env, name, STACK_SIZE, Thread::Location(), Thread::Weight(), cpu) { }
|
2014-09-05 17:00:31 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2014-09-05 17:00:31 +02:00
|
|
|
{
|
|
|
|
while (1) {
|
2016-05-04 12:27:17 +02:00
|
|
|
/*
|
|
|
|
* Don't log here, since this thread becomes "paused".
|
|
|
|
* If it is holding the lock of the log backend being paused, all
|
|
|
|
* other threads of this task trying to print log messages will
|
2014-09-05 17:00:31 +02:00
|
|
|
* block - looks like a deadlock.
|
|
|
|
*/
|
|
|
|
loop ++;
|
|
|
|
if (beep) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
log("beep");
|
2014-09-05 17:00:31 +02:00
|
|
|
beep = false;
|
2015-07-21 17:02:22 +02:00
|
|
|
loop ++;
|
|
|
|
return;
|
2014-09-05 17:00:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
|
|
|
|
static void test_pause_resume(Env &env)
|
2014-09-05 17:00:31 +02:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Pause_helper thread(env, "pause", env.cpu());
|
2014-09-05 17:00:31 +02:00
|
|
|
thread.start();
|
|
|
|
|
|
|
|
while (thread.loop < 1) { }
|
|
|
|
|
|
|
|
Thread_state state;
|
2016-05-10 18:05:38 +02:00
|
|
|
Cpu_thread_client thread_client(thread.cap());
|
2014-09-05 17:00:31 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- pausing ---");
|
2016-05-10 18:05:38 +02:00
|
|
|
thread_client.pause();
|
2014-09-05 17:00:31 +02:00
|
|
|
unsigned loop_paused = thread.loop;
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- paused ---");
|
2014-09-05 17:00:31 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- reading thread state ---");
|
2014-09-05 17:00:31 +02:00
|
|
|
try {
|
2016-05-10 18:05:38 +02:00
|
|
|
state = thread_client.state();
|
|
|
|
} catch (Cpu_thread::State_access_failed) {
|
2014-09-05 17:00:31 +02:00
|
|
|
throw -10;
|
|
|
|
}
|
|
|
|
if (loop_paused != thread.loop)
|
|
|
|
throw -11;
|
|
|
|
|
|
|
|
thread.beep = true;
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- resuming thread ---");
|
2016-05-10 18:05:38 +02:00
|
|
|
thread_client.resume();
|
2014-09-05 17:00:31 +02:00
|
|
|
|
|
|
|
while (thread.loop == loop_paused) { }
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- thread resumed ---");
|
2015-07-21 17:02:22 +02:00
|
|
|
thread.join();
|
2014-09-05 17:00:31 +02:00
|
|
|
}
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
|
2015-07-21 17:02:22 +02:00
|
|
|
/*
|
|
|
|
* Test to check that core as the used kernel behaves well if up to the
|
|
|
|
* supported Genode maximum threads are created.
|
|
|
|
*/
|
2016-05-04 12:27:17 +02:00
|
|
|
static void test_create_as_many_threads(Env &env)
|
2015-07-21 17:02:22 +02:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("running '", __func__, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
addr_t const max = Thread::stack_area_virtual_size() /
|
|
|
|
Thread::stack_virtual_size();
|
2015-07-21 17:02:22 +02:00
|
|
|
|
2016-03-03 17:57:29 +01:00
|
|
|
Cpu_helper * threads[max];
|
2015-07-21 17:02:22 +02:00
|
|
|
static char thread_name[8];
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Heap heap(env.ram(), env.rm());
|
|
|
|
|
2015-07-21 17:02:22 +02:00
|
|
|
unsigned i = 0;
|
|
|
|
try {
|
|
|
|
for (; i < max; i++) {
|
|
|
|
try {
|
|
|
|
snprintf(thread_name, sizeof(thread_name), "%u", i + 1);
|
2016-05-04 12:27:17 +02:00
|
|
|
threads[i] = new (heap) Cpu_helper(env, thread_name, env.cpu());
|
2015-07-21 17:02:22 +02:00
|
|
|
threads[i]->start();
|
|
|
|
threads[i]->join();
|
|
|
|
} catch (Cpu_session::Thread_creation_failed) {
|
|
|
|
throw "Thread_creation_failed";
|
2016-05-04 12:27:17 +02:00
|
|
|
} catch (Thread::Out_of_stack_space) {
|
2016-01-23 14:42:55 +01:00
|
|
|
throw "Out_of_stack_space";
|
2016-11-14 15:38:17 +01:00
|
|
|
} catch (Genode::Native_capability::Reference_count_overflow) {
|
|
|
|
throw "Native_capability::Reference_count_overflow";
|
2015-07-21 17:02:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (const char * ex) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
log("created ", i, " threads before I got '", ex, "'");
|
2015-07-21 17:02:22 +02:00
|
|
|
for (unsigned j = i; j > 0; j--) {
|
2016-05-04 12:27:17 +02:00
|
|
|
destroy(heap, threads[j - 1]);
|
2015-07-21 17:02:22 +02:00
|
|
|
threads[j - 1] = nullptr;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-01-23 14:42:55 +01:00
|
|
|
* We have to get a Out_of_stack_space message, because we can't create
|
2015-07-21 17:02:22 +02:00
|
|
|
* up to max threads, because already the main thread is running ...
|
|
|
|
*/
|
|
|
|
throw -21;
|
|
|
|
}
|
2014-09-05 17:00:31 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
|
2017-03-01 14:00:52 +01:00
|
|
|
/*********************************
|
|
|
|
** Using Locks in creative ways *
|
|
|
|
*********************************/
|
|
|
|
|
|
|
|
struct Lock_helper : Thread
|
|
|
|
{
|
2020-02-19 16:26:40 +01:00
|
|
|
Blockade &lock;
|
|
|
|
bool &lock_is_free;
|
|
|
|
bool unlock;
|
2017-03-01 14:00:52 +01:00
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
Lock_helper(Env &env, const char * name, Cpu_session &cpu, Blockade &lock,
|
2017-03-01 14:00:52 +01:00
|
|
|
bool &lock_is_free, bool unlock = false)
|
|
|
|
:
|
|
|
|
Thread(env, name, STACK_SIZE, Thread::Location(), Thread::Weight(),
|
|
|
|
cpu),
|
|
|
|
lock(lock), lock_is_free(lock_is_free), unlock(unlock)
|
|
|
|
{ }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2017-03-01 14:00:52 +01:00
|
|
|
{
|
|
|
|
log(" thread '", name(), "' started");
|
|
|
|
|
|
|
|
if (unlock)
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.wakeup();
|
2017-03-01 14:00:52 +01:00
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.block();
|
2017-03-01 14:00:52 +01:00
|
|
|
|
|
|
|
if (!lock_is_free) {
|
|
|
|
log(" thread '", name(), "' got lock but somebody else is within"
|
|
|
|
" critical section !?");
|
|
|
|
throw -22;
|
|
|
|
}
|
|
|
|
|
|
|
|
log(" thread '", name(), "' done");
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.wakeup();
|
2017-03-01 14:00:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_locks(Genode::Env &env)
|
|
|
|
{
|
2020-02-19 16:26:40 +01:00
|
|
|
Blockade lock;
|
2017-03-01 14:00:52 +01:00
|
|
|
|
|
|
|
bool lock_is_free = true;
|
|
|
|
|
|
|
|
Cpu_connection cpu_m(env, "prio middle", Cpu_session::PRIORITY_LIMIT / 4);
|
|
|
|
Cpu_connection cpu_l(env, "prio low", Cpu_session::PRIORITY_LIMIT / 2);
|
|
|
|
|
|
|
|
enum { SYNC_STARTUP = true };
|
|
|
|
|
|
|
|
Lock_helper l1(env, "lock_low1", cpu_l, lock, lock_is_free);
|
|
|
|
Lock_helper l2(env, "lock_low2", cpu_l, lock, lock_is_free);
|
|
|
|
Lock_helper l3(env, "lock_low3", cpu_l, lock, lock_is_free);
|
|
|
|
Lock_helper l4(env, "lock_low4", cpu_l, lock, lock_is_free, SYNC_STARTUP);
|
|
|
|
|
|
|
|
l1.start();
|
|
|
|
l2.start();
|
|
|
|
l3.start();
|
|
|
|
l4.start();
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.block();
|
2017-03-01 14:00:52 +01:00
|
|
|
|
|
|
|
log(" thread '", Thread::myself()->name(), "' - I'm the lock holder - "
|
|
|
|
"take lock again");
|
|
|
|
|
|
|
|
/* we are within the critical section - lock is not free */
|
|
|
|
lock_is_free = false;
|
|
|
|
|
|
|
|
/* start another low prio thread to wake current thread when it blocks */
|
|
|
|
Lock_helper l5(env, "lock_low5", cpu_l, lock, lock_is_free, SYNC_STARTUP);
|
|
|
|
l5.start();
|
|
|
|
|
2017-06-16 16:27:56 +02:00
|
|
|
log(" spin for some time");
|
|
|
|
for (unsigned volatile i = 0; i < 8000000; ++i) memory_barrier();
|
|
|
|
log(" still spinning");
|
|
|
|
for (unsigned volatile i = 0; i < 8000000; ++i) memory_barrier();
|
|
|
|
log(" spinning done");
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.block();
|
2017-03-01 14:00:52 +01:00
|
|
|
log(" I'm the lock holder - still alive");
|
|
|
|
lock_is_free = true;
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
lock.wakeup();
|
2017-03-01 14:00:52 +01:00
|
|
|
|
|
|
|
/* check that really all threads come back ! */
|
|
|
|
l1.join();
|
|
|
|
l2.join();
|
|
|
|
l3.join();
|
|
|
|
l4.join();
|
|
|
|
l5.join();
|
|
|
|
|
|
|
|
log("running '", __func__, "' done");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-01 21:52:00 +01:00
|
|
|
/**********************************
|
|
|
|
** Using cxa guards concurrently *
|
|
|
|
**********************************/
|
|
|
|
|
|
|
|
struct Cxa_helper : Thread
|
|
|
|
{
|
2020-02-19 16:26:40 +01:00
|
|
|
Blockade &in_cxa;
|
|
|
|
Blockade &sync_startup;
|
|
|
|
int test;
|
|
|
|
bool sync;
|
2017-03-01 21:52:00 +01:00
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
Cxa_helper(Env &env, const char * name, Cpu_session &cpu, Blockade &cxa,
|
|
|
|
Blockade &startup, int test, bool sync = false)
|
2017-03-01 21:52:00 +01:00
|
|
|
:
|
|
|
|
Thread(env, name, STACK_SIZE, Thread::Location(), Thread::Weight(),
|
|
|
|
cpu),
|
|
|
|
in_cxa(cxa), sync_startup(startup), test(test), sync(sync)
|
|
|
|
{ }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2017-03-01 21:52:00 +01:00
|
|
|
{
|
|
|
|
log(" thread '", name(), "' started");
|
|
|
|
|
|
|
|
if (sync)
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup.wakeup();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
struct Contention {
|
2020-02-19 16:26:40 +01:00
|
|
|
Contention(Name name, Blockade &in_cxa, Blockade &sync_startup)
|
2017-03-01 21:52:00 +01:00
|
|
|
{
|
|
|
|
log(" thread '", name, "' in static constructor");
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup.wakeup();
|
|
|
|
in_cxa.block();
|
2017-03-01 21:52:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (test == 1)
|
|
|
|
static Contention contention (name(), in_cxa, sync_startup);
|
|
|
|
else
|
|
|
|
if (test == 2)
|
|
|
|
static Contention contention (name(), in_cxa, sync_startup);
|
|
|
|
else
|
|
|
|
if (test == 3)
|
|
|
|
static Contention contention (name(), in_cxa, sync_startup);
|
|
|
|
else
|
|
|
|
if (test == 4)
|
|
|
|
static Contention contention (name(), in_cxa, sync_startup);
|
|
|
|
else
|
|
|
|
throw -25;
|
|
|
|
|
|
|
|
log(" thread '", name(), "' done");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_cxa_guards(Env &env)
|
|
|
|
{
|
|
|
|
log("running '", __func__, "'");
|
|
|
|
|
|
|
|
Cpu_connection cpu_m(env, "prio middle", Cpu_session::PRIORITY_LIMIT / 4);
|
|
|
|
Cpu_connection cpu_l(env, "prio low", Cpu_session::PRIORITY_LIMIT / 2);
|
|
|
|
|
|
|
|
{
|
|
|
|
enum { TEST_1ST = 1 };
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
Blockade in_cxa;
|
|
|
|
Blockade sync_startup;
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* start low priority thread */
|
|
|
|
Cxa_helper cxa_l(env, "cxa_low", cpu_l, in_cxa, sync_startup, TEST_1ST);
|
|
|
|
cxa_l.start();
|
|
|
|
|
|
|
|
/* wait until low priority thread is inside static variable */
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup.block();
|
|
|
|
sync_startup.wakeup();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* start high priority threads */
|
|
|
|
Cxa_helper cxa_h1(env, "cxa_high_1", env.cpu(), in_cxa, sync_startup,
|
|
|
|
TEST_1ST);
|
|
|
|
Cxa_helper cxa_h2(env, "cxa_high_2", env.cpu(), in_cxa, sync_startup,
|
|
|
|
TEST_1ST);
|
|
|
|
Cxa_helper cxa_h3(env, "cxa_high_3", env.cpu(), in_cxa, sync_startup,
|
|
|
|
TEST_1ST);
|
|
|
|
Cxa_helper cxa_h4(env, "cxa_high_4", env.cpu(), in_cxa, sync_startup,
|
|
|
|
TEST_1ST);
|
|
|
|
cxa_h1.start();
|
|
|
|
cxa_h2.start();
|
|
|
|
cxa_h3.start();
|
|
|
|
cxa_h4.start();
|
|
|
|
|
|
|
|
/* start middle priority thread */
|
|
|
|
enum { SYNC_STARTUP = true };
|
|
|
|
Cxa_helper cxa_m(env, "cxa_middle", cpu_m, in_cxa, sync_startup,
|
|
|
|
TEST_1ST, SYNC_STARTUP);
|
|
|
|
cxa_m.start();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* high priority threads are for sure in the static Contention variable,
|
|
|
|
* if the middle priority thread manages to sync with current
|
|
|
|
* (high priority) entrypoint thread
|
|
|
|
*/
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup.block();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* let's see whether we get all our threads out of the static variable */
|
2020-02-19 16:26:40 +01:00
|
|
|
in_cxa.wakeup();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* eureka ! */
|
|
|
|
cxa_h1.join(); cxa_h2.join(); cxa_h3.join(); cxa_h4.join();
|
|
|
|
cxa_m.join();
|
|
|
|
cxa_l.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
enum { TEST_2ND = 2, TEST_3RD = 3, TEST_4TH = 4 };
|
|
|
|
|
2020-02-19 16:26:40 +01:00
|
|
|
Blockade in_cxa_2;
|
|
|
|
Blockade sync_startup_2;
|
|
|
|
Blockade in_cxa_3;
|
|
|
|
Blockade sync_startup_3;
|
|
|
|
Blockade in_cxa_4;
|
|
|
|
Blockade sync_startup_4;
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* start low priority threads */
|
|
|
|
Cxa_helper cxa_l_2(env, "cxa_low_2", cpu_l, in_cxa_2, sync_startup_2,
|
|
|
|
TEST_2ND);
|
|
|
|
Cxa_helper cxa_l_3(env, "cxa_low_3", cpu_l, in_cxa_3, sync_startup_3,
|
|
|
|
TEST_3RD);
|
|
|
|
Cxa_helper cxa_l_4(env, "cxa_low_4", cpu_l, in_cxa_4, sync_startup_4,
|
|
|
|
TEST_4TH);
|
|
|
|
cxa_l_2.start();
|
|
|
|
cxa_l_3.start();
|
|
|
|
cxa_l_4.start();
|
|
|
|
|
|
|
|
/* wait until low priority threads are inside static variables */
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup_2.block();
|
|
|
|
sync_startup_2.wakeup();
|
|
|
|
sync_startup_3.block();
|
|
|
|
sync_startup_3.wakeup();
|
|
|
|
sync_startup_4.block();
|
|
|
|
sync_startup_4.wakeup();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* start high priority threads */
|
|
|
|
Cxa_helper cxa_h1_2(env, "cxa_high_1_2", env.cpu(), in_cxa_2,
|
|
|
|
sync_startup_2, TEST_2ND);
|
|
|
|
Cxa_helper cxa_h2_2(env, "cxa_high_2_2", env.cpu(), in_cxa_2,
|
|
|
|
sync_startup_2, TEST_2ND);
|
|
|
|
Cxa_helper cxa_h3_2(env, "cxa_high_3_2", env.cpu(), in_cxa_2,
|
|
|
|
sync_startup_2, TEST_2ND);
|
|
|
|
Cxa_helper cxa_h4_2(env, "cxa_high_4_2", env.cpu(), in_cxa_2,
|
|
|
|
sync_startup_2, TEST_2ND);
|
|
|
|
|
|
|
|
Cxa_helper cxa_h1_3(env, "cxa_high_1_3", env.cpu(), in_cxa_3,
|
|
|
|
sync_startup_3, TEST_3RD);
|
|
|
|
Cxa_helper cxa_h2_3(env, "cxa_high_2_3", env.cpu(), in_cxa_3,
|
|
|
|
sync_startup_3, TEST_3RD);
|
|
|
|
Cxa_helper cxa_h3_3(env, "cxa_high_3_3", env.cpu(), in_cxa_3,
|
|
|
|
sync_startup_3, TEST_3RD);
|
|
|
|
Cxa_helper cxa_h4_3(env, "cxa_high_4_3", env.cpu(), in_cxa_3,
|
|
|
|
sync_startup_3, TEST_3RD);
|
|
|
|
|
|
|
|
Cxa_helper cxa_h1_4(env, "cxa_high_1_4", env.cpu(), in_cxa_4,
|
|
|
|
sync_startup_4, TEST_4TH);
|
|
|
|
Cxa_helper cxa_h2_4(env, "cxa_high_2_4", env.cpu(), in_cxa_4,
|
|
|
|
sync_startup_4, TEST_4TH);
|
|
|
|
Cxa_helper cxa_h3_4(env, "cxa_high_3_4", env.cpu(), in_cxa_4,
|
|
|
|
sync_startup_4, TEST_4TH);
|
|
|
|
Cxa_helper cxa_h4_4(env, "cxa_high_4_4", env.cpu(), in_cxa_4,
|
|
|
|
sync_startup_4, TEST_4TH);
|
|
|
|
|
|
|
|
cxa_h1_2.start(); cxa_h1_3.start(); cxa_h1_4.start();
|
|
|
|
cxa_h2_2.start(); cxa_h2_3.start(); cxa_h2_4.start();
|
|
|
|
cxa_h3_2.start(); cxa_h3_3.start(); cxa_h3_4.start();
|
|
|
|
cxa_h4_2.start(); cxa_h4_3.start(); cxa_h4_4.start();
|
|
|
|
|
|
|
|
/* start middle priority threads */
|
|
|
|
enum { SYNC_STARTUP = true };
|
|
|
|
Cxa_helper cxa_m_2(env, "cxa_middle_2", cpu_m, in_cxa_2,
|
|
|
|
sync_startup_2, TEST_2ND, SYNC_STARTUP);
|
|
|
|
Cxa_helper cxa_m_3(env, "cxa_middle_3", cpu_m, in_cxa_3,
|
|
|
|
sync_startup_3, TEST_3RD, SYNC_STARTUP);
|
|
|
|
Cxa_helper cxa_m_4(env, "cxa_middle_4", cpu_m, in_cxa_4,
|
|
|
|
sync_startup_4, TEST_4TH, SYNC_STARTUP);
|
|
|
|
|
|
|
|
cxa_m_2.start();
|
|
|
|
cxa_m_3.start();
|
|
|
|
cxa_m_4.start();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* high priority threads are for sure in the static Contention
|
|
|
|
* variables, if the middle priority threads manage to sync with
|
|
|
|
* current (high priority) entrypoint thread
|
|
|
|
*/
|
2020-02-19 16:26:40 +01:00
|
|
|
sync_startup_2.block();
|
|
|
|
sync_startup_3.block();
|
|
|
|
sync_startup_4.block();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
/* let's see whether we get all our threads out of the static variable */
|
2020-02-19 16:26:40 +01:00
|
|
|
in_cxa_4.wakeup();
|
|
|
|
in_cxa_3.wakeup();
|
|
|
|
in_cxa_2.wakeup();
|
2017-03-01 21:52:00 +01:00
|
|
|
|
|
|
|
cxa_h1_2.join(); cxa_h2_2.join(); cxa_h3_2.join(); cxa_h4_2.join();
|
|
|
|
cxa_m_2.join(); cxa_l_2.join();
|
|
|
|
|
|
|
|
cxa_h1_3.join(); cxa_h2_3.join(); cxa_h3_3.join(); cxa_h4_3.join();
|
|
|
|
cxa_m_3.join(); cxa_l_3.join();
|
|
|
|
|
|
|
|
cxa_h1_4.join(); cxa_h2_4.join(); cxa_h3_4.join(); cxa_h4_4.join();
|
|
|
|
cxa_m_4.join(); cxa_l_4.join();
|
|
|
|
}
|
|
|
|
log("running '", __func__, "' done");
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:02:12 +02:00
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
** Successive construction and destruction **
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
|
struct Create_destroy_helper : Thread
|
|
|
|
{
|
|
|
|
unsigned const result_value;
|
|
|
|
unsigned volatile result { ~0U };
|
|
|
|
|
|
|
|
Create_destroy_helper(Env &env, unsigned result_value)
|
|
|
|
: Thread(env, "create_destroy", STACK_SIZE),
|
|
|
|
result_value(result_value)
|
|
|
|
{ }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2018-06-26 15:02:12 +02:00
|
|
|
{
|
|
|
|
result = result_value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_successive_create_destroy_threads(Env &env)
|
|
|
|
{
|
|
|
|
log("running '", __func__, "'");
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 500; i++) {
|
|
|
|
Create_destroy_helper thread(env, i);
|
|
|
|
thread.start();
|
|
|
|
thread.join();
|
|
|
|
if (thread.result != i)
|
|
|
|
throw -30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:35:00 +01:00
|
|
|
/******************************************************
|
|
|
|
** Test destruction of inter-dependent CPU sessions **
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
static void test_destroy_dependent_cpu_sessions(Env &env)
|
|
|
|
{
|
|
|
|
log("destroy dependent CPU sessions in wrong order");
|
|
|
|
|
|
|
|
Cpu_connection grandchild { env };
|
|
|
|
Cpu_connection child { env };
|
|
|
|
|
|
|
|
grandchild.ref_account(child.rpc_cap());
|
|
|
|
|
|
|
|
/* when leaving the scope, 'child' is destructed before 'grandchild' */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Component::construct(Env &env)
|
2014-01-10 17:32:20 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
log("--- thread test started ---");
|
|
|
|
|
2016-05-10 14:06:38 +02:00
|
|
|
Attached_rom_dataspace config(env, "config");
|
2014-04-29 10:57:39 +02:00
|
|
|
|
2014-01-10 17:32:20 +01:00
|
|
|
try {
|
2019-12-06 13:35:00 +01:00
|
|
|
|
|
|
|
test_destroy_dependent_cpu_sessions(env);
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
test_stack_alloc(env);
|
|
|
|
test_stack_alignment(env);
|
2014-02-05 17:05:32 +01:00
|
|
|
test_main_thread();
|
2016-05-04 12:27:17 +02:00
|
|
|
test_cpu_session(env);
|
2017-06-16 16:27:56 +02:00
|
|
|
if (config.xml().attribute_value("prio", false)) {
|
|
|
|
test_locks(env);
|
|
|
|
test_cxa_guards(env);
|
|
|
|
}
|
|
|
|
if (config.xml().attribute_value("pause_resume", false))
|
2016-05-04 12:27:17 +02:00
|
|
|
test_pause_resume(env);
|
|
|
|
|
|
|
|
test_create_as_many_threads(env);
|
2018-06-26 15:02:12 +02:00
|
|
|
test_successive_create_destroy_threads(env);
|
2014-01-10 17:32:20 +01:00
|
|
|
} catch (int error) {
|
2016-05-04 12:27:17 +02:00
|
|
|
Genode::error("error ", error);
|
|
|
|
throw;
|
2014-01-10 17:32:20 +01:00
|
|
|
}
|
2016-05-04 12:27:17 +02:00
|
|
|
|
|
|
|
log("--- test completed successfully ---");
|
2013-12-02 10:24:35 +01:00
|
|
|
}
|