Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
maestro-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maestro
maestro-core
Commits
963e88e7
Commit
963e88e7
authored
5 years ago
by
Utz-Uwe Haus
Browse files
Options
Downloads
Patches
Plain Diff
[MAMBA] Protect allocator factory by lock
parent
d29539ae
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
deps/mamba/configure.ac
+9
-0
9 additions, 0 deletions
deps/mamba/configure.ac
deps/mamba/m4/ax_pthread.m4
+486
-0
486 additions, 0 deletions
deps/mamba/m4/ax_pthread.m4
deps/mamba/memory/allocation.c
+56
-12
56 additions, 12 deletions
deps/mamba/memory/allocation.c
with
551 additions
and
12 deletions
deps/mamba/configure.ac
+
9
−
0
View file @
963e88e7
...
@@ -59,6 +59,15 @@ dnl Keep a backup of LDFLAGS and CFLAGS so it is not modified except for lib che
...
@@ -59,6 +59,15 @@ dnl Keep a backup of LDFLAGS and CFLAGS so it is not modified except for lib che
CFLAGS_backup="${CFLAGS}"
CFLAGS_backup="${CFLAGS}"
LDFLAGS_backup="${LDFLAGS}"
LDFLAGS_backup="${LDFLAGS}"
dnl pthread checks on Cray CC need this to have _REENTRANT defined
CPPFLAGS+=" -D_REENTRANT"
AX_PTHREAD([
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
],[AC_MSG_FAILURE([Need pthread library])])
dnl LANL/SICM support
dnl LANL/SICM support
AC_ARG_WITH([sicm],
AC_ARG_WITH([sicm],
[AS_HELP_STRING([--with-sicm@<:@=/path/to/sicm/install@:>@],
[AS_HELP_STRING([--with-sicm@<:@=/path/to/sicm/install@:>@],
...
...
This diff is collapsed.
Click to expand it.
deps/mamba/m4/ax_pthread.m4
0 → 100644
+
486
−
0
View file @
963e88e7
This diff is collapsed.
Click to expand it.
deps/mamba/memory/allocation.c
+
56
−
12
View file @
963e88e7
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#include
<stddef.h>
#include
<stddef.h>
#include
<stdbool.h>
#include
<stdbool.h>
#include
<string.h>
#include
<string.h>
#include
<pthread.h>
#include
<assert.h>
#include
"mmb_error.h"
#include
"mmb_error.h"
#include
"mmb_logging.h"
#include
"mmb_logging.h"
...
@@ -50,7 +52,21 @@ typedef struct mmbAllocationFactory {
...
@@ -50,7 +52,21 @@ typedef struct mmbAllocationFactory {
}
mmbAllocationFactory
;
}
mmbAllocationFactory
;
static
mmbAllocationFactory
*
global_factory
=
NULL
;
static
mmbAllocationFactory
*
global_factory
=
NULL
;
/* protecting global_factory */
pthread_mutex_t
global_factory_mtx
=
PTHREAD_MUTEX_INITIALIZER
;
#define LOCK_GLOBAL_FACTORY do { \
DEBUG("Locking global factory\n"); \
int _gflstat = pthread_mutex_lock(&global_factory_mtx); \
assert(_gflstat==0); \
} while(0);
#define UNLOCK_GLOBAL_FACTORY do { \
DEBUG("Unlocking global factory\n"); \
int _gflstat = pthread_mutex_unlock(&global_factory_mtx); \
assert(_gflstat==0); \
} while(0);
/* must be called under lock */
static
mmbError
mmb_alloc_factory_new
(
mmbAllocationFactory
**
out_factory
)
static
mmbError
mmb_alloc_factory_new
(
mmbAllocationFactory
**
out_factory
)
{
{
/* Check parameter */
/* Check parameter */
...
@@ -69,6 +85,7 @@ static mmbError mmb_alloc_factory_new(mmbAllocationFactory **out_factory)
...
@@ -69,6 +85,7 @@ static mmbError mmb_alloc_factory_new(mmbAllocationFactory **out_factory)
return
MMB_OK
;
return
MMB_OK
;
}
}
/* must be called under lock */
static
mmbError
mmb_alloc_factory_delete
(
mmbAllocationFactory
*
in_factory
)
static
mmbError
mmb_alloc_factory_delete
(
mmbAllocationFactory
*
in_factory
)
{
{
/* Check parameter */
/* Check parameter */
...
@@ -115,9 +132,11 @@ mmbError mmb_alloc_check_params(const mmbAllocation *alloc)
...
@@ -115,9 +132,11 @@ mmbError mmb_alloc_check_params(const mmbAllocation *alloc)
mmbError
mmb_alloc_initialize
(
void
)
mmbError
mmb_alloc_initialize
(
void
)
{
{
mmbError
stat
=
MMB_OK
;
mmbError
stat
=
MMB_OK
;
LOCK_GLOBAL_FACTORY
;
if
(
NULL
==
global_factory
)
{
if
(
NULL
==
global_factory
)
{
stat
=
mmb_alloc_factory_new
(
&
global_factory
);
stat
=
mmb_alloc_factory_new
(
&
global_factory
);
}
}
UNLOCK_GLOBAL_FACTORY
;
return
stat
;
return
stat
;
}
}
...
@@ -125,15 +144,21 @@ mmbError mmb_alloc_finalize(void)
...
@@ -125,15 +144,21 @@ mmbError mmb_alloc_finalize(void)
{
{
mmbError
stat
;
mmbError
stat
;
mmbAllocationFactory
*
fact
=
NULL
;
mmbAllocationFactory
*
fact
=
NULL
;
LOCK_GLOBAL_FACTORY
;
for
(;
NULL
!=
global_factory
;
global_factory
=
fact
)
{
for
(;
NULL
!=
global_factory
;
global_factory
=
fact
)
{
fact
=
global_factory
->
next
;
fact
=
global_factory
->
next
;
stat
=
mmb_alloc_factory_delete
(
global_factory
);
stat
=
mmb_alloc_factory_delete
(
global_factory
);
if
(
MMB_OK
!=
stat
)
{
if
(
MMB_OK
!=
stat
)
{
WARN
(
"Error when deallocating the mmbAllocation factory.
\n
"
);
WARN
(
"Error when deallocating the mmbAllocation factory.
\n
"
);
return
stat
;
goto
BAILOUT_UNLOCK
;
}
}
}
}
return
MMB_OK
;
BAILOUT_UNLOCK:
UNLOCK_GLOBAL_FACTORY
;
return
stat
;
}
}
mmbError
mmb_alloc_allocate
(
void
*
ptr
,
const
size_t
n_bytes
,
mmbError
mmb_alloc_allocate
(
void
*
ptr
,
const
size_t
n_bytes
,
...
@@ -141,14 +166,20 @@ mmbError mmb_alloc_allocate(void *ptr, const size_t n_bytes,
...
@@ -141,14 +166,20 @@ mmbError mmb_alloc_allocate(void *ptr, const size_t n_bytes,
const
bool
owned
,
mmbAllocation
**
alloc
)
const
bool
owned
,
mmbAllocation
**
alloc
)
{
{
/* Check parameter */
/* Check parameter */
if
(
NULL
==
global_factory
)
{
mmbError
stat
;
ERR
(
"Factory not initialized.
\n
"
);
return
MMB_INVALID_ARG
;
}
if
(
NULL
==
alloc
)
{
if
(
NULL
==
alloc
)
{
ERR
(
"Out parameter
\"
alloc
\"
cannot be NULL.
\n
"
);
ERR
(
"Out parameter
\"
alloc
\"
cannot be NULL.
\n
"
);
return
MMB_INVALID_ARG
;
return
MMB_INVALID_ARG
;
}
}
LOCK_GLOBAL_FACTORY
;
if
(
NULL
==
global_factory
)
{
ERR
(
"Factory not initialized.
\n
"
);
stat
=
MMB_INVALID_ARG
;
goto
BAILOUT_UNLOCK
;
}
/* Look for an available slot */
/* Look for an available slot */
mmbAllocationFactory
*
last
=
NULL
,
*
factory
=
global_factory
;
mmbAllocationFactory
*
last
=
NULL
,
*
factory
=
global_factory
;
mmbAllocation
*
new_alloc
=
NULL
;
mmbAllocation
*
new_alloc
=
NULL
;
...
@@ -169,10 +200,10 @@ mmbError mmb_alloc_allocate(void *ptr, const size_t n_bytes,
...
@@ -169,10 +200,10 @@ mmbError mmb_alloc_allocate(void *ptr, const size_t n_bytes,
}
}
/* if this point is reached no suitable available entry has been found.
/* if this point is reached no suitable available entry has been found.
* Allocate a new set of mmbAllocation's. */
* Allocate a new set of mmbAllocation's. */
mmbError
stat
=
mmb_alloc_factory_new
(
&
last
->
next
);
stat
=
mmb_alloc_factory_new
(
&
last
->
next
);
if
(
MMB_OK
!=
stat
)
{
if
(
MMB_OK
!=
stat
)
{
WARN
(
"Unable to allocate new set of mmbAllocation. Allocation fails.
\n
"
);
WARN
(
"Unable to allocate new set of mmbAllocation. Allocation fails.
\n
"
);
return
stat
;
goto
BAILOUT_UNLOCK
;
}
}
new_alloc
=
&
last
->
next
->
ptrs
[
0
][
0
];
new_alloc
=
&
last
->
next
->
ptrs
[
0
][
0
];
last
->
next
->
avail
[
0
]
&=
~
1
;
last
->
next
->
avail
[
0
]
&=
~
1
;
...
@@ -183,7 +214,12 @@ SET_AND_OUT:
...
@@ -183,7 +214,12 @@ SET_AND_OUT:
new_alloc
->
interface
=
interface
;
new_alloc
->
interface
=
interface
;
new_alloc
->
owned
=
owned
;
new_alloc
->
owned
=
owned
;
*
alloc
=
new_alloc
;
*
alloc
=
new_alloc
;
return
MMB_OK
;
stat
=
MMB_OK
;
BAILOUT_UNLOCK:
UNLOCK_GLOBAL_FACTORY
;
return
stat
;
}
}
mmbError
mmb_alloc_free
(
mmbAllocation
*
alloc
)
mmbError
mmb_alloc_free
(
mmbAllocation
*
alloc
)
...
@@ -195,9 +231,12 @@ mmbError mmb_alloc_free(mmbAllocation *alloc)
...
@@ -195,9 +231,12 @@ mmbError mmb_alloc_free(mmbAllocation *alloc)
WARN
(
"Invalid
\"
alloc
\"
handle.
\n
"
);
WARN
(
"Invalid
\"
alloc
\"
handle.
\n
"
);
return
MMB_INVALID_ALLOCATION
;
return
MMB_INVALID_ALLOCATION
;
}
}
LOCK_GLOBAL_FACTORY
;
if
(
NULL
==
global_factory
)
{
if
(
NULL
==
global_factory
)
{
ERR
(
"Factory not initialized.
\n
"
);
ERR
(
"Factory not initialized.
\n
"
);
return
MMB_INVALID_ARG
;
stat
=
MMB_INVALID_ARG
;
goto
BAILOUT_UNLOCK
;
}
}
/* Find proper set that contains the allocated alloc. */
/* Find proper set that contains the allocated alloc. */
for
(
mmbAllocationFactory
*
factory
=
global_factory
;
for
(
mmbAllocationFactory
*
factory
=
global_factory
;
...
@@ -208,10 +247,15 @@ mmbError mmb_alloc_free(mmbAllocation *alloc)
...
@@ -208,10 +247,15 @@ mmbError mmb_alloc_free(mmbAllocation *alloc)
const
size_t
block
=
offset
/
(
8
*
sizeof
(
unsigned
int
));
const
size_t
block
=
offset
/
(
8
*
sizeof
(
unsigned
int
));
const
size_t
index
=
offset
%
(
8
*
sizeof
(
unsigned
int
));
const
size_t
index
=
offset
%
(
8
*
sizeof
(
unsigned
int
));
factory
->
avail
[
block
]
|=
1
<<
index
;
factory
->
avail
[
block
]
|=
1
<<
index
;
return
MMB_OK
;
stat
=
MMB_OK
;
goto
BAILOUT_UNLOCK
;
}
}
}
}
/* Could not find the proper set : incoherent state that should have happen */
/* Could not find the proper set : incoherent state that should have happen */
ERR
(
"Impossible to find the corresponding mmbAllocation record.
\n
"
);
ERR
(
"Impossible to find the corresponding mmbAllocation record.
\n
"
);
return
MMB_ERROR
;
stat
=
MMB_ERROR
;
BAILOUT_UNLOCK:
UNLOCK_GLOBAL_FACTORY
;
return
stat
;
}
}
This diff is collapsed.
Click to expand it.
Utz-Uwe Haus
@haus1
mentioned in commit
fab8d9ef
·
5 years ago
mentioned in commit
fab8d9ef
mentioned in commit fab8d9ef0ae5fdd35e5840b811e44d182cb24b6e
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment