mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-11 18:06:13 +00:00
Reduce memory cost in entry_table
Original code double entry table space if there is no space. It may waste 50% memory of the entry table. Now we use a link list to store entry items.
This commit is contained in:
parent
f02a1ed427
commit
c19f8338d7
@ -116,47 +116,27 @@ static void free_register_table(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char **entry_point_table = NULL;
|
struct entry_point_item {
|
||||||
int entry_point_table_length = 0;
|
char *str;
|
||||||
|
struct entry_point_item *next;
|
||||||
|
} *entry_point_table;
|
||||||
|
|
||||||
#define DEFAULTBUFSIZE 800
|
|
||||||
static int read_entry_file(char *fn)
|
static int read_entry_file(char *fn)
|
||||||
{
|
{
|
||||||
FILE *entry_table_file;
|
FILE *entry_table_file;
|
||||||
char buf[DEFAULTBUFSIZE];
|
char buf[2048];
|
||||||
char *ptr;
|
struct entry_point_item **p = &entry_point_table;
|
||||||
int curr_table_length = 80;
|
if (!fn)
|
||||||
if (!fn) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
if ((entry_table_file = fopen(fn, "r")) == NULL)
|
||||||
if ((entry_point_table =
|
return -1;
|
||||||
malloc(curr_table_length*sizeof(char*))) == NULL) {
|
while (fgets(buf, sizeof(buf)-1, entry_table_file) != NULL) {
|
||||||
return 1;
|
// drop the final char '\n'
|
||||||
}
|
if(buf[strlen(buf)-1] == '\n')
|
||||||
|
buf[strlen(buf)-1] = 0;
|
||||||
entry_table_file = fopen(fn, "r");
|
*p = calloc(1, sizeof(struct entry_point_item));
|
||||||
if (!entry_table_file) {
|
(*p)->str = strdup(buf);
|
||||||
return 1;
|
p = &((*p)->next);
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
int size = DEFAULTBUFSIZE;
|
|
||||||
if((ptr = fgets(buf, size, entry_table_file))==NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf[strlen(buf)-1] = '\0';
|
|
||||||
if(entry_point_table_length == curr_table_length)
|
|
||||||
{
|
|
||||||
if ((entry_point_table = realloc(entry_point_table,
|
|
||||||
curr_table_length*2*sizeof(char*))) == NULL) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
curr_table_length *= 2;
|
|
||||||
}
|
|
||||||
entry_point_table[entry_point_table_length] = strdup(buf);
|
|
||||||
entry_point_table_length ++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(entry_table_file);
|
fclose(entry_table_file);
|
||||||
return 0;
|
return 0;
|
||||||
@ -164,15 +144,22 @@ static int read_entry_file(char *fn)
|
|||||||
|
|
||||||
static int is_entry_point(char *s)
|
static int is_entry_point(char *s)
|
||||||
{
|
{
|
||||||
int i;
|
struct entry_point_item *p;
|
||||||
for (i = 0; i < entry_point_table_length; i++) {
|
for (p = entry_point_table; p; p = p->next) {
|
||||||
if (strcmp(entry_point_table[i], s) == 0) {
|
if (strcmp(p->str, s) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_entry_point_table(struct entry_point_item *p) {
|
||||||
|
if (p) {
|
||||||
|
free_entry_point_table(p->next);
|
||||||
|
free(p->str);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_instruction(FILE *output, struct brw_program_instruction *entry)
|
print_instruction(FILE *output, struct brw_program_instruction *entry)
|
||||||
{
|
{
|
||||||
@ -379,6 +366,7 @@ int main(int argc, char **argv)
|
|||||||
if (binary_like_output)
|
if (binary_like_output)
|
||||||
fprintf(output, "};");
|
fprintf(output, "};");
|
||||||
|
|
||||||
|
free_entry_point_table(entry_point_table);
|
||||||
free_register_table();
|
free_register_table();
|
||||||
fflush (output);
|
fflush (output);
|
||||||
if (ferror (output)) {
|
if (ferror (output)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user