Skip to content

Commit b148766

Browse files
committed
parisc: Reduce kernel size by packing alternative tables
The values stored in the length and condition fields of the alternative tables fit into 16 bits, so we can save 4 bytes per alternative table entry. Since a typical 32-bit kernel has more than 3000 entries this saves > 12k of storage on disc. bloat-o-meter shows a reduction of -0.01% by this change: Total: Before=10196505, After=10195529, chg -0.01% $ ls -la vmlinux vmlinux.before -rwxr-xr-x 14437324 vmlinux -rwxr-xr-x 14449512 vmlinux.before Signed-off-by: Helge Deller <[email protected]>
1 parent 4fe89d0 commit b148766

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

arch/parisc/include/asm/alternative.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
struct alt_instr {
2424
s32 orig_offset; /* offset to original instructions */
25-
s32 len; /* end of original instructions */
26-
u32 cond; /* see ALT_COND_XXX */
25+
s16 len; /* end of original instructions */
26+
u16 cond; /* see ALT_COND_XXX */
2727
u32 replacement; /* replacement instruction or code */
28-
};
28+
} __packed;
2929

3030
void set_kernel_text_rw(int enable_read_write);
3131
void apply_alternatives_all(void);
@@ -35,24 +35,27 @@ void apply_alternatives(struct alt_instr *start, struct alt_instr *end,
3535
/* Alternative SMP implementation. */
3636
#define ALTERNATIVE(cond, replacement) "!0:" \
3737
".section .altinstructions, \"aw\" !" \
38-
".word (0b-4-.), 1, " __stringify(cond) "," \
39-
__stringify(replacement) " !" \
38+
".word (0b-4-.) !" \
39+
".hword 1, " __stringify(cond) " !" \
40+
".word " __stringify(replacement) " !" \
4041
".previous"
4142

4243
#else
4344

4445
/* to replace one single instructions by a new instruction */
4546
#define ALTERNATIVE(from, to, cond, replacement)\
4647
.section .altinstructions, "aw" ! \
47-
.word (from - .), (to - from)/4 ! \
48-
.word cond, replacement ! \
48+
.word (from - .) ! \
49+
.hword (to - from)/4, cond ! \
50+
.word replacement ! \
4951
.previous
5052

5153
/* to replace multiple instructions by new code */
5254
#define ALTERNATIVE_CODE(from, num_instructions, cond, new_instr_ptr)\
5355
.section .altinstructions, "aw" ! \
54-
.word (from - .), -num_instructions ! \
55-
.word cond, (new_instr_ptr - .) ! \
56+
.word (from - .) ! \
57+
.hword -num_instructions, cond ! \
58+
.word (new_instr_ptr - .) ! \
5659
.previous
5760

5861
#endif /* __ASSEMBLY__ */

arch/parisc/kernel/alternative.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
2626
struct alt_instr *entry;
2727
int index = 0, applied = 0;
2828
int num_cpus = num_online_cpus();
29-
u32 cond_check;
29+
u16 cond_check;
3030

3131
cond_check = ALT_COND_ALWAYS |
3232
((num_cpus == 1) ? ALT_COND_NO_SMP : 0) |
@@ -45,8 +45,9 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
4545

4646
for (entry = start; entry < end; entry++, index++) {
4747

48-
u32 *from, cond, replacement;
49-
s32 len;
48+
u32 *from, replacement;
49+
u16 cond;
50+
s16 len;
5051

5152
from = (u32 *)((ulong)&entry->orig_offset + entry->orig_offset);
5253
len = entry->len;

0 commit comments

Comments
 (0)