Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
codes
codes
Commits
836505c8
Commit
836505c8
authored
Jul 15, 2014
by
Jonathan Jenkins
Browse files
resource LP now fully annotation-aware
parent
ef8494c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
codes/configuration.h
View file @
836505c8
...
...
@@ -209,6 +209,15 @@ int configuration_get_lpgroups (ConfigHandle *handle,
const
char
*
section_name
,
config_lpgroups_t
*
lpgroups
);
/*
* Helper function - get the position in the LP annotation list of the
* given annotation. Used for configuration schemes where an array of
* configuration values is generated based on the annotations in
* config_anno_map_t
* If annotation is not found, -1 is returned */
int
configuration_get_annotation_index
(
const
char
*
anno
,
const
config_anno_map_t
*
anno_map
);
/*
* Forward reference to the configuration handle
*/
...
...
codes/resource-lp.h
View file @
836505c8
...
...
@@ -18,6 +18,8 @@
#define RESOURCE_MAX_CALLBACK_PAYLOAD 64
#define RESOURCE_LP_NM "resource"
typedef
struct
{
int
ret
;
/* in the case of a reserve, need to return the token */
...
...
src/util/configuration.c
View file @
836505c8
...
...
@@ -387,6 +387,22 @@ int configuration_get_lpgroups (ConfigHandle *handle,
return
0
;
}
/*
* Helper function - get the position in the LP annotation list of the
* given annotation. Used for configuration schemes where an array of
* configuration values is generated based on the annotations in
* config_anno_map_t
* If annotation is not found, -1 is returned */
int
configuration_get_annotation_index
(
const
char
*
anno
,
const
config_anno_map_t
*
anno_map
){
for
(
uint64_t
i
=
0
;
i
<
anno_map
->
num_annos
;
i
++
){
if
(
strcmp
(
anno
,
anno_map
->
annotations
[
i
])
==
0
){
return
(
int
)
i
;
}
}
return
-
1
;
}
/*
* Local variables:
* c-indent-level: 4
...
...
src/util/resource-lp.c
View file @
836505c8
...
...
@@ -7,6 +7,7 @@
#include
"codes/resource-lp.h"
#include
"codes/resource.h"
#include
"codes/codes_mapping.h"
#include
"codes/configuration.h"
#include
"codes/jenkins-hash.h"
#include
"codes/quicklist.h"
#include
"codes/lp-io.h"
...
...
@@ -19,10 +20,11 @@
/**** BEGIN SIMULATION DATA STRUCTURES ****/
static
int
resource_magic
;
/* use this as sanity check on events */
/* TODO: we currently use a single config value to initialize the resource unit
* count for all resources in the system. Later on, we'll want to do this on a
* per-group basis */
static
uint64_t
avail_global
;
/* configuration globals (will be consumed by LP when they init) */
static
uint64_t
avail_unanno
;
static
uint64_t
*
avail_per_anno
;
static
const
config_anno_map_t
*
anno_map
;
typedef
struct
resource_state
resource_state
;
typedef
struct
resource_msg
resource_msg
;
...
...
@@ -123,8 +125,21 @@ static tw_lptype resource_lp = {
void
resource_lp_ind_init
(
resource_state
*
ns
,
tw_lp
*
lp
){
/* currently use global to initialize, may need to have other LPs init */
resource_init
(
avail_global
,
&
ns
->
r
);
// get my annotation
const
char
*
anno
=
codes_mapping_get_annotation_by_lpid
(
lp
->
gid
);
if
(
anno
==
NULL
){
resource_init
(
avail_unanno
,
&
ns
->
r
);
}
else
{
int
idx
=
configuration_get_annotation_index
(
anno
,
anno_map
);
if
(
idx
<
0
){
tw_error
(
"resource LP %lu: unable to find annotation "
"%s in configuration
\n
"
,
lp
->
gid
,
anno
);
}
else
{
resource_init
(
avail_per_anno
[
idx
],
&
ns
->
r
);
}
}
int
i
;
for
(
i
=
0
;
i
<
MAX_RESERVE
+
1
;
i
++
){
INIT_QLIST_HEAD
(
&
ns
->
pending
[
i
]);
...
...
@@ -404,7 +419,7 @@ void resource_finalize(
if
(
codes_mapping_get_lp_global_rel_id
(
lp
->
gid
)
==
0
){
written
=
sprintf
(
out_buf
,
"# format: <LP> <max used general> <max used token...>
\n
"
);
lp_io_write
(
lp
->
gid
,
"resource"
,
written
,
out_buf
);
lp_io_write
(
lp
->
gid
,
RESOURCE_LP_NM
,
written
,
out_buf
);
}
written
=
sprintf
(
out_buf
,
"%lu"
,
lp
->
gid
);
...
...
@@ -414,7 +429,7 @@ void resource_finalize(
written
+=
sprintf
(
out_buf
+
written
,
" %lu"
,
ns
->
r
.
max
[
i
]
-
ns
->
r
.
min_avail
[
i
]);
}
written
+=
sprintf
(
out_buf
+
written
,
"
\n
"
);
lp_io_write
(
lp
->
gid
,
"resource"
,
written
,
out_buf
);
lp_io_write
(
lp
->
gid
,
RESOURCE_LP_NM
,
written
,
out_buf
);
}
/**** END IMPLEMENTATIONS ****/
...
...
@@ -423,23 +438,45 @@ void resource_finalize(
void
resource_lp_init
(){
uint32_t
h1
=
0
,
h2
=
0
;
bj_hashlittle2
(
"resource"
,
strlen
(
"resource"
),
&
h1
,
&
h2
);
bj_hashlittle2
(
RESOURCE_LP_NM
,
strlen
(
RESOURCE_LP_NM
),
&
h1
,
&
h2
);
resource_magic
=
h1
+
h2
;
lp_type_register
(
"resource"
,
&
resource_lp
);
lp_type_register
(
RESOURCE_LP_NM
,
&
resource_lp
);
}
void
resource_lp_configure
(){
anno_map
=
codes_mapping_get_lp_anno_map
(
RESOURCE_LP_NM
);
avail_per_anno
=
(
anno_map
->
num_annos
>
0
)
?
malloc
(
anno_map
->
num_annos
*
sizeof
(
*
avail_per_anno
))
:
NULL
;
// get the unannotated version
long
int
avail
;
int
ret
=
configuration_get_value_longint
(
&
config
,
"resource"
,
int
ret
;
if
(
anno_map
->
num_unanno_lps
>
0
){
ret
=
configuration_get_value_longint
(
&
config
,
RESOURCE_LP_NM
,
"available"
,
NULL
,
&
avail
);
if
(
ret
){
fprintf
(
stderr
,
"Could not find section:resource value:available for "
"resource LP
\n
"
);
exit
(
1
);
if
(
ret
){
fprintf
(
stderr
,
"Could not find section:resource value:available for "
"resource LP
\n
"
);
exit
(
1
);
}
assert
(
avail
>
0
);
avail_unanno
=
(
uint64_t
)
avail
;
}
for
(
uint64_t
i
=
0
;
i
<
anno_map
->
num_annos
;
i
++
){
ret
=
configuration_get_value_longint
(
&
config
,
RESOURCE_LP_NM
,
"available"
,
anno_map
->
annotations
[
i
],
&
avail
);
if
(
ret
){
fprintf
(
stderr
,
"Could not find section:resource value:available@%s for "
"resource LP
\n
"
,
anno_map
->
annotations
[
i
]);
exit
(
1
);
}
assert
(
avail
>
0
);
avail_per_anno
[
i
]
=
(
uint64_t
)
avail
;
}
assert
(
avail
>
0
);
avail_global
=
(
uint64_t
)
avail
;
}
static
void
resource_lp_issue_event
(
...
...
@@ -464,7 +501,7 @@ static void resource_lp_issue_event(
codes_mapping_get_lp_info
(
sender
->
gid
,
lp_group_name
,
&
mapping_grp_id
,
&
mapping_type_id
,
lp_type_name
,
&
mapping_rep_id
,
&
mapping_offset
);
codes_mapping_get_lp_id
(
lp_group_name
,
"resource"
,
mapping_rep_id
,
codes_mapping_get_lp_id
(
lp_group_name
,
RESOURCE_LP_NM
,
mapping_rep_id
,
mapping_offset
,
&
resource_lpid
);
tw_event
*
e
=
codes_event_new
(
resource_lpid
,
codes_local_latency
(
sender
),
...
...
src/util/resource.c
View file @
836505c8
...
...
@@ -22,7 +22,7 @@ void resource_init(uint64_t avail, resource *r){
for
(
int
i
=
1
;
i
<
MAX_RESERVE
;
i
++
){
r
->
avail
[
i
]
=
0
;
r
->
max
[
i
]
=
0
;
r
->
min_avail
[
i
]
=
avail
;
r
->
min_avail
[
i
]
=
0
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment