forked from mirrors/linux
		
	scripts/kallsyms: shrink table before sorting it
Currently, build_initial_tok_table() trims unused symbols, but it is called after sort_symbols(). It is not efficient to sort the huge table that contains unused entries. Shrink the table before sorting it. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
		
							parent
							
								
									21915eca08
								
							
						
					
					
						commit
						5e5c4fa787
					
				
					 1 changed files with 29 additions and 20 deletions
				
			
		| 
						 | 
					@ -268,6 +268,30 @@ static int symbol_valid(struct sym_entry *s)
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* remove all the invalid symbols from the table */
 | 
				
			||||||
 | 
					static void shrink_table(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int i, pos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pos = 0;
 | 
				
			||||||
 | 
						for (i = 0; i < table_cnt; i++) {
 | 
				
			||||||
 | 
							if (symbol_valid(&table[i])) {
 | 
				
			||||||
 | 
								if (pos != i)
 | 
				
			||||||
 | 
									table[pos] = table[i];
 | 
				
			||||||
 | 
								pos++;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								free(table[i].sym);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						table_cnt = pos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* When valid symbol is not registered, exit to error */
 | 
				
			||||||
 | 
						if (!table_cnt) {
 | 
				
			||||||
 | 
							fprintf(stderr, "No valid symbol.\n");
 | 
				
			||||||
 | 
							exit(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void read_map(FILE *in)
 | 
					static void read_map(FILE *in)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	while (!feof(in)) {
 | 
						while (!feof(in)) {
 | 
				
			||||||
| 
						 | 
					@ -475,23 +499,13 @@ static void forget_symbol(unsigned char *symbol, int len)
 | 
				
			||||||
		token_profit[ symbol[i] + (symbol[i + 1] << 8) ]--;
 | 
							token_profit[ symbol[i] + (symbol[i + 1] << 8) ]--;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* remove all the invalid symbols from the table and do the initial token count */
 | 
					/* do the initial token count */
 | 
				
			||||||
static void build_initial_tok_table(void)
 | 
					static void build_initial_tok_table(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned int i, pos;
 | 
						unsigned int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pos = 0;
 | 
						for (i = 0; i < table_cnt; i++)
 | 
				
			||||||
	for (i = 0; i < table_cnt; i++) {
 | 
							learn_symbol(table[i].sym, table[i].len);
 | 
				
			||||||
		if ( symbol_valid(&table[i]) ) {
 | 
					 | 
				
			||||||
			if (pos != i)
 | 
					 | 
				
			||||||
				table[pos] = table[i];
 | 
					 | 
				
			||||||
			learn_symbol(table[pos].sym, table[pos].len);
 | 
					 | 
				
			||||||
			pos++;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			free(table[i].sym);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	table_cnt = pos;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void *find_token(unsigned char *str, int len, unsigned char *token)
 | 
					static void *find_token(unsigned char *str, int len, unsigned char *token)
 | 
				
			||||||
| 
						 | 
					@ -614,12 +628,6 @@ static void optimize_token_table(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	insert_real_symbols_in_table();
 | 
						insert_real_symbols_in_table();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* When valid symbol is not registered, exit to error */
 | 
					 | 
				
			||||||
	if (!table_cnt) {
 | 
					 | 
				
			||||||
		fprintf(stderr, "No valid symbol.\n");
 | 
					 | 
				
			||||||
		exit(1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	optimize_result();
 | 
						optimize_result();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -756,6 +764,7 @@ int main(int argc, char **argv)
 | 
				
			||||||
		usage();
 | 
							usage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	read_map(stdin);
 | 
						read_map(stdin);
 | 
				
			||||||
 | 
						shrink_table();
 | 
				
			||||||
	if (absolute_percpu)
 | 
						if (absolute_percpu)
 | 
				
			||||||
		make_percpus_absolute();
 | 
							make_percpus_absolute();
 | 
				
			||||||
	if (base_relative)
 | 
						if (base_relative)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue