Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Slurm
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tud-zih-energy
Slurm
Commits
c6dc6345
Commit
c6dc6345
authored
22 years ago
by
tewk
Browse files
Options
Downloads
Patches
Plain Diff
Buffer can now be initialized with custom min, max and increment numbers
parent
b68c18e4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/slurmd/circular_buffer.c
+47
-20
47 additions, 20 deletions
src/slurmd/circular_buffer.c
src/slurmd/circular_buffer.h
+7
-3
7 additions, 3 deletions
src/slurmd/circular_buffer.h
with
54 additions
and
23 deletions
src/slurmd/circular_buffer.c
+
47
−
20
View file @
c6dc6345
...
@@ -7,15 +7,16 @@
...
@@ -7,15 +7,16 @@
#include
<src/slurmd/circular_buffer.h>
#include
<src/slurmd/circular_buffer.h>
#define
BUFFER_FULL_DUMP_SIZE 4096
#define
DEF_INITIAL_BUFFER_SIZE 8192
#define
INITI
AL_BUFFER_SIZE 8192
#define
DEF_INCREMENT
AL_BUFFER_SIZE 8192
#define
INCREMENTAL
_BUFFER_SIZE
8192
#define
DEF_MAX
_BUFFER_SIZE
( ( 8192 * 10 ) )
#define
MAX_
BUFFER_
SIZE ( ( 8192 * 10 )
)
#define BUFFER_
FULL_DUMP_SIZE ( buf -> min_size / 2
)
static
int
assert_checks
(
circular_buffer_t
*
buf
)
;
static
int
assert_checks
(
circular_buffer_t
*
buf
)
;
static
int
assert_checks_2
(
circular_buffer_t
*
buf
)
;
static
int
assert_checks_2
(
circular_buffer_t
*
buf
)
;
static
int
expand_buffer
(
circular_buffer_t
*
buf
)
;
static
int
expand_buffer
(
circular_buffer_t
*
buf
)
;
static
int
shrink_buffer
(
circular_buffer_t
*
buf
)
;
static
int
shrink_buffer
(
circular_buffer_t
*
buf
)
;
static
void
common_init
(
circular_buffer_t
*
buf
)
;
void
free_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
void
free_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
{
{
...
@@ -34,8 +35,34 @@ int init_circular_buffer ( circular_buffer_t ** buf_ptr )
...
@@ -34,8 +35,34 @@ int init_circular_buffer ( circular_buffer_t ** buf_ptr )
circular_buffer_t
*
buf
;
circular_buffer_t
*
buf
;
*
buf_ptr
=
xmalloc
(
sizeof
(
circular_buffer_t
)
)
;
*
buf_ptr
=
xmalloc
(
sizeof
(
circular_buffer_t
)
)
;
buf
=
*
buf_ptr
;
buf
=
*
buf_ptr
;
buf
->
buffer
=
xmalloc
(
INITIAL_BUFFER_SIZE
)
;
buf
->
buf_size
=
INITIAL_BUFFER_SIZE
;
buf
->
min_size
=
DEF_INITIAL_BUFFER_SIZE
;
buf
->
max_size
=
DEF_MAX_BUFFER_SIZE
;
buf
->
incremental_size
=
DEF_INCREMENTAL_BUFFER_SIZE
;
common_init
(
buf
)
;
return
SLURM_SUCCESS
;
}
int
init_circular_buffer2
(
circular_buffer_t
**
buf_ptr
,
int
min_size
,
int
max_size
,
int
incremental_size
)
{
circular_buffer_t
*
buf
;
*
buf_ptr
=
xmalloc
(
sizeof
(
circular_buffer_t
)
)
;
buf
=
*
buf_ptr
;
buf
->
min_size
=
min_size
;
buf
->
max_size
=
max_size
;
buf
->
incremental_size
=
incremental_size
;
common_init
(
buf
)
;
return
SLURM_SUCCESS
;
}
static
void
common_init
(
circular_buffer_t
*
buf
)
{
buf
->
buffer
=
xmalloc
(
buf
->
min_size
)
;
buf
->
buf_size
=
buf
->
min_size
;
buf
->
start
=
buf
->
buffer
;
buf
->
start
=
buf
->
buffer
;
buf
->
end
=
buf
->
start
+
buf
->
buf_size
;
buf
->
end
=
buf
->
start
+
buf
->
buf_size
;
...
@@ -44,8 +71,9 @@ int init_circular_buffer ( circular_buffer_t ** buf_ptr )
...
@@ -44,8 +71,9 @@ int init_circular_buffer ( circular_buffer_t ** buf_ptr )
buf
->
tail
=
buf
->
start
;
buf
->
tail
=
buf
->
start
;
buf
->
read_size
=
0
;
buf
->
read_size
=
0
;
buf
->
write_size
=
INITIAL_BUFFER_SIZE
;
buf
->
write_size
=
buf
->
min_size
;
return
SLURM_SUCCESS
;
return
;
}
}
void
print_circular_buffer
(
circular_buffer_t
*
buf
)
void
print_circular_buffer
(
circular_buffer_t
*
buf
)
...
@@ -222,7 +250,6 @@ static int assert_checks ( circular_buffer_t * buf )
...
@@ -222,7 +250,6 @@ static int assert_checks ( circular_buffer_t * buf )
{
{
/* sanity checks */
/* sanity checks */
/* insures that dump data when MAX_BUFFER_SIZE is full will work correctly */
/* insures that dump data when MAX_BUFFER_SIZE is full will work correctly */
assert
(
BUFFER_FULL_DUMP_SIZE
<=
INITIAL_BUFFER_SIZE
/
2
)
;
assert
(
buf
!=
NULL
)
;
/* buf struct is not null */
assert
(
buf
!=
NULL
)
;
/* buf struct is not null */
assert
(
buf
->
start
==
buf
->
buffer
);
/* stat hasn't moved */
assert
(
buf
->
start
==
buf
->
buffer
);
/* stat hasn't moved */
...
@@ -244,7 +271,7 @@ static int shrink_buffer ( circular_buffer_t * buf )
...
@@ -244,7 +271,7 @@ static int shrink_buffer ( circular_buffer_t * buf )
{
{
char
*
new_buffer
;
char
*
new_buffer
;
if
(
buf
->
buf_size
==
INITIAL_BUFFER_SIZE
)
if
(
buf
->
buf_size
==
buf
->
min_size
)
{
{
/* info ( "circular buffer at minimum" ) ; */
/* info ( "circular buffer at minimum" ) ; */
...
@@ -252,25 +279,25 @@ static int shrink_buffer ( circular_buffer_t * buf )
...
@@ -252,25 +279,25 @@ static int shrink_buffer ( circular_buffer_t * buf )
buf
->
tail
=
buf
->
start
;
buf
->
tail
=
buf
->
start
;
buf
->
read_size
=
0
;
buf
->
read_size
=
0
;
buf
->
write_size
=
INITIAL_BUFFER_SIZE
;
buf
->
write_size
=
buf
->
min_size
;
return
SLURM_SUCCESS
;
return
SLURM_SUCCESS
;
}
}
else
else
{
{
new_buffer
=
xmalloc
(
INITIAL_BUFFER_SIZE
)
;
new_buffer
=
xmalloc
(
buf
->
min_size
)
;
xfree
(
buf
->
buffer
)
;
xfree
(
buf
->
buffer
)
;
buf
->
buffer
=
new_buffer
;
buf
->
buffer
=
new_buffer
;
buf
->
buf_size
=
INITIAL_BUFFER_SIZE
;
buf
->
buf_size
=
buf
->
min_size
;
buf
->
start
=
new_buffer
;
buf
->
start
=
new_buffer
;
buf
->
end
=
new_buffer
+
INITIAL_BUFFER_SIZE
;
buf
->
end
=
new_buffer
+
buf
->
min_size
;
buf
->
head
=
new_buffer
;
buf
->
head
=
new_buffer
;
buf
->
tail
=
new_buffer
;
buf
->
tail
=
new_buffer
;
buf
->
read_size
=
0
;
buf
->
read_size
=
0
;
buf
->
write_size
=
INITIAL_BUFFER_SIZE
;
buf
->
write_size
=
buf
->
min_size
;
return
SLURM_SUCCESS
;
return
SLURM_SUCCESS
;
}
}
...
@@ -286,7 +313,7 @@ static int expand_buffer ( circular_buffer_t * buf )
...
@@ -286,7 +313,7 @@ static int expand_buffer ( circular_buffer_t * buf )
/* info ( "EXPANDING BUFFER" ) ; */
/* info ( "EXPANDING BUFFER" ) ; */
/*print_circular_buffer ( buf ) ; */
/*print_circular_buffer ( buf ) ; */
if
(
buf
->
buf_size
==
MAX_BUFFER_SIZE
)
if
(
buf
->
buf_size
==
buf
->
max_size
)
{
{
/*print_circular_buffer ( buf ) ; */
/*print_circular_buffer ( buf ) ; */
/*info ( "circular buffer maxed, dumping BUFFER_FULL_DUMP_SIZE of data"); */
/*info ( "circular buffer maxed, dumping BUFFER_FULL_DUMP_SIZE of data"); */
...
@@ -318,7 +345,7 @@ static int expand_buffer ( circular_buffer_t * buf )
...
@@ -318,7 +345,7 @@ static int expand_buffer ( circular_buffer_t * buf )
if
(
buf
->
tail
>
buf
->
head
)
if
(
buf
->
tail
>
buf
->
head
)
{
{
new_buffer
=
xmalloc
(
buf
->
buf_size
+
INCREMENTAL_BUFFER_SIZE
)
;
new_buffer
=
xmalloc
(
buf
->
buf_size
+
buf
->
incremental_size
)
;
data_size
=
buf
->
tail
-
buf
->
head
;
data_size
=
buf
->
tail
-
buf
->
head
;
memcpy
(
new_buffer
,
buf
->
head
,
data_size
)
;
memcpy
(
new_buffer
,
buf
->
head
,
data_size
)
;
xfree
(
buf
->
buffer
)
;
xfree
(
buf
->
buffer
)
;
...
@@ -326,7 +353,7 @@ static int expand_buffer ( circular_buffer_t * buf )
...
@@ -326,7 +353,7 @@ static int expand_buffer ( circular_buffer_t * buf )
}
}
else
if
(
buf
->
tail
<=
buf
->
head
)
/* CASE B */
else
if
(
buf
->
tail
<=
buf
->
head
)
/* CASE B */
{
{
new_buffer
=
xmalloc
(
buf
->
buf_size
+
INCREMENTAL_BUFFER_SIZE
)
;
new_buffer
=
xmalloc
(
buf
->
buf_size
+
buf
->
incremental_size
)
;
data_size_blk1
=
buf
->
end
-
buf
->
head
;
data_size_blk1
=
buf
->
end
-
buf
->
head
;
data_size_blk2
=
buf
->
tail
-
buf
->
start
;
data_size_blk2
=
buf
->
tail
-
buf
->
start
;
data_size
=
data_size_blk1
+
data_size_blk2
;
data_size
=
data_size_blk1
+
data_size_blk2
;
...
@@ -345,8 +372,8 @@ static int expand_buffer ( circular_buffer_t * buf )
...
@@ -345,8 +372,8 @@ static int expand_buffer ( circular_buffer_t * buf )
buf
->
start
=
new_buffer
;
buf
->
start
=
new_buffer
;
buf
->
head
=
new_buffer
;
buf
->
head
=
new_buffer
;
buf
->
tail
=
new_buffer
+
data_size
;
buf
->
tail
=
new_buffer
+
data_size
;
buf
->
end
=
new_buffer
+
buf
->
buf_size
+
INCREMENTAL_BUFFER_SIZE
;
buf
->
end
=
new_buffer
+
buf
->
buf_size
+
buf
->
incremental_size
;
buf
->
buf_size
+=
INCREMENTAL_BUFFER_SIZE
;
buf
->
buf_size
+=
buf
->
incremental_size
;
buf
->
read_size
=
data_size
;
buf
->
read_size
=
data_size
;
buf
->
write_size
=
buf
->
end
-
buf
->
tail
;
buf
->
write_size
=
buf
->
end
-
buf
->
tail
;
...
...
This diff is collapsed.
Click to expand it.
src/slurmd/circular_buffer.h
+
7
−
3
View file @
c6dc6345
...
@@ -10,11 +10,15 @@ typedef struct circular_buffer
...
@@ -10,11 +10,15 @@ typedef struct circular_buffer
unsigned
int
write_size
;
/* buffer size that can be written */
unsigned
int
write_size
;
/* buffer size that can be written */
char
*
head
;
/* beginning of the used portion of the buffer */
char
*
head
;
/* beginning of the used portion of the buffer */
char
*
tail
;
/* end of the used portion of the buffer */
char
*
tail
;
/* end of the used portion of the buffer */
unsigned
int
min_size
;
unsigned
int
max_size
;
unsigned
int
incremental_size
;
}
circular_buffer_t
;
}
circular_buffer_t
;
int
init_circular_buffer
(
circular_buffer_t
**
buf_ptr
)
;
int
inline
init_circular_buffer2
(
circular_buffer_t
**
buf_ptr
,
int
min_size
,
int
max_size
,
int
incremental_size
)
;
void
free_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
;
int
inline
init_circular_buffer
(
circular_buffer_t
**
buf_ptr
)
;
void
print_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
;
void
inline
free_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
;
void
inline
print_circular_buffer
(
circular_buffer_t
*
buf_ptr
)
;
int
cir_buf_read_update
(
circular_buffer_t
*
buf
,
unsigned
int
size
)
;
int
cir_buf_read_update
(
circular_buffer_t
*
buf
,
unsigned
int
size
)
;
int
cir_buf_write_update
(
circular_buffer_t
*
buf
,
unsigned
int
size
)
;
int
cir_buf_write_update
(
circular_buffer_t
*
buf
,
unsigned
int
size
)
;
#endif
#endif
This diff is collapsed.
Click to expand it.
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