The ROme OpTimistic Simulator
2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
Main Page
Data Structures
Files
File List
Globals
ult.c
Go to the documentation of this file.
1
40
#include <stdio.h>
41
#include <stdlib.h>
42
#include <string.h>
43
#include <stdbool.h>
44
45
#include <
arch/ult.h
>
46
#include <
core/core.h
>
47
#include <
scheduler/process.h
>
48
#include <
mm/dymelor.h
>
49
51
__thread
kernel_context_t
kernel_context
;
52
53
#if defined(OS_LINUX)
54
65
void
*
get_ult_stack
(
size_t
size)
66
{
67
void
*stack;
68
size_t
reminder;
69
size_t
page_size;
70
71
// Sanity check
72
if
(
unlikely
(size <= 0)) {
73
size = LP_STACK_SIZE;
74
}
75
// Align the size to the page boundary (by increasing the stack size)
76
page_size = getpagesize();
77
reminder = size % page_size;
78
if
(
unlikely
(reminder != 0)) {
79
size += page_size - reminder;
80
}
81
// The first call to the LP malloc subsystem gives page-aligned memory
82
stack = rsalloc(size);
83
if
(stack == NULL) {
84
rootsim_error(
true
,
85
"Error allocating LP stack: not enough memory.\n"
);
86
}
87
88
bzero(stack, size);
89
90
return
stack;
91
}
92
93
#elif defined(OS_WINDOWS) || defined(OS_CYGWIN)
94
95
void
context_create
(
LP_context_t
* context,
void
(*entry_point)(
void
*),
void
*args,
void
*stack,
size_t
stack_size)
96
{
97
98
(void)stack;
99
100
// BUG? was this intended to be used when the contexts were setup by a single thread?
101
static
bool
once =
false
;
102
103
if
(
unlikely
(once ==
false
)) {
104
once =
true
;
105
// Convert the current thread to a fiber. This allows to schedule other fibers.
106
kernel_context
.jb = ConvertThreadToFiber(NULL);
107
}
108
// Create a new fiber
109
context->jb = CreateFiber(stack_size, (LPFIBER_START_ROUTINE) entry_point, args);
110
}
111
112
#endif
/* OS */
context_create
void context_create(exec_context_t *creat, void(*fn)(void *), void *args, void *stack, size_t stack_size)
ult.h
User-Level Threads Headers.
core.h
Core ROOT-Sim functionalities.
dymelor.h
Dynamic Memory Logger and Restorer (DyMeLoR)
get_ult_stack
void * get_ult_stack(size_t size)
Definition:
ult.c:65
kernel_context
__thread kernel_context_t kernel_context
This is the execution context of the simulation kernel.
Definition:
ult.c:51
process.h
LP control blocks.
unlikely
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition:
core.h:74
__exec_context_t
This structure describes the CPU context of a User-Level Thread.
Definition:
jmp.h:42
src
arch
ult.c
Generated by
1.8.11