Skip to content

Commit 9fec9f8

Browse files
mzaslonkakpm00
authored andcommitted
lib/zlib: Split deflate and inflate states for DFLTCC
Currently deflate and inflate both use a common state struct. There are several variables in this struct that we don't need for inflate, and more may be coming in the future. Therefore split them in two separate structs. Apart from that, introduce separate headers for dfltcc_deflate and dfltcc_inflate. This commit is based on: zlib-ng/zlib-ng@c592b1b Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mikhail Zaslonko <[email protected]> Acked-by: Ilya Leoshkevich <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Vasily Gorbik <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cbf1254 commit 9fec9f8

File tree

8 files changed

+110
-76
lines changed

8 files changed

+110
-76
lines changed

lib/zlib_deflate/deflate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
/* architecture-specific bits */
5656
#ifdef CONFIG_ZLIB_DFLTCC
57-
# include "../zlib_dfltcc/dfltcc.h"
57+
# include "../zlib_dfltcc/dfltcc_deflate.h"
5858
#else
5959
#define DEFLATE_RESET_HOOK(strm) do {} while (0)
6060
#define DEFLATE_HOOK(strm, flush, bstate) 0
@@ -106,7 +106,7 @@ typedef struct deflate_workspace {
106106
deflate_state deflate_memory;
107107
#ifdef CONFIG_ZLIB_DFLTCC
108108
/* State memory for s390 hardware deflate */
109-
struct dfltcc_state dfltcc_memory;
109+
struct dfltcc_deflate_state dfltcc_memory;
110110
#endif
111111
Byte *window_memory;
112112
Pos *prev_memory;

lib/zlib_dfltcc/dfltcc.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,18 @@ char *oesc_msg(
2323
}
2424
}
2525

26-
void dfltcc_reset(
27-
z_streamp strm,
28-
uInt size
29-
)
30-
{
31-
struct dfltcc_state *dfltcc_state =
32-
(struct dfltcc_state *)((char *)strm->state + size);
33-
struct dfltcc_qaf_param *param =
34-
(struct dfltcc_qaf_param *)&dfltcc_state->param;
35-
26+
void dfltcc_reset_state(struct dfltcc_state *dfltcc_state) {
3627
/* Initialize available functions */
3728
if (is_dfltcc_enabled()) {
38-
dfltcc(DFLTCC_QAF, param, NULL, NULL, NULL, NULL, NULL);
39-
memmove(&dfltcc_state->af, param, sizeof(dfltcc_state->af));
29+
dfltcc(DFLTCC_QAF, &dfltcc_state->param, NULL, NULL, NULL, NULL, NULL);
30+
memmove(&dfltcc_state->af, &dfltcc_state->param, sizeof(dfltcc_state->af));
4031
} else
4132
memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
4233

4334
/* Initialize parameter block */
4435
memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param));
4536
dfltcc_state->param.nt = 1;
46-
47-
/* Initialize tuning parameters */
48-
if (zlib_dfltcc_support == ZLIB_DFLTCC_FULL_DEBUG)
49-
dfltcc_state->level_mask = DFLTCC_LEVEL_MASK_DEBUG;
50-
else
51-
dfltcc_state->level_mask = DFLTCC_LEVEL_MASK;
52-
dfltcc_state->block_size = DFLTCC_BLOCK_SIZE;
53-
dfltcc_state->block_threshold = DFLTCC_FIRST_FHT_BLOCK_SIZE;
54-
dfltcc_state->dht_threshold = DFLTCC_DHT_MIN_SAMPLE_SIZE;
5537
dfltcc_state->param.ribm = DFLTCC_RIBM;
5638
}
57-
EXPORT_SYMBOL(dfltcc_reset);
5839

5940
MODULE_LICENSE("GPL");

lib/zlib_dfltcc/dfltcc.h

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,64 +93,32 @@ static_assert(sizeof(struct dfltcc_param_v0) == 1536);
9393
struct dfltcc_state {
9494
struct dfltcc_param_v0 param; /* Parameter block */
9595
struct dfltcc_qaf_param af; /* Available functions */
96+
char msg[64]; /* Buffer for strm->msg */
97+
};
98+
99+
/*
100+
* Extension of inflate_state and deflate_state for DFLTCC.
101+
*/
102+
struct dfltcc_deflate_state {
103+
struct dfltcc_state common; /* Parameter block */
96104
uLong level_mask; /* Levels on which to use DFLTCC */
97105
uLong block_size; /* New block each X bytes */
98106
uLong block_threshold; /* New block after total_in > X */
99107
uLong dht_threshold; /* New block only if avail_in >= X */
100-
char msg[64]; /* Buffer for strm->msg */
101108
};
102109

103110
#define ALIGN_UP(p, size) (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1))
104111
/* Resides right after inflate_state or deflate_state */
105112
#define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((char *)(state) + ALIGN_UP(sizeof(*state), 8)))
106113

107-
/* External functions */
108-
int dfltcc_can_deflate(z_streamp strm);
109-
int dfltcc_deflate(z_streamp strm,
110-
int flush,
111-
block_state *result);
112-
void dfltcc_reset(z_streamp strm, uInt size);
113-
int dfltcc_can_inflate(z_streamp strm);
114-
typedef enum {
115-
DFLTCC_INFLATE_CONTINUE,
116-
DFLTCC_INFLATE_BREAK,
117-
DFLTCC_INFLATE_SOFTWARE,
118-
} dfltcc_inflate_action;
119-
dfltcc_inflate_action dfltcc_inflate(z_streamp strm,
120-
int flush, int *ret);
114+
void dfltcc_reset_state(struct dfltcc_state *dfltcc_state);
115+
121116
static inline int is_dfltcc_enabled(void)
122117
{
123118
return (zlib_dfltcc_support != ZLIB_DFLTCC_DISABLED &&
124119
test_facility(DFLTCC_FACILITY));
125120
}
126121

127-
#define DEFLATE_RESET_HOOK(strm) \
128-
dfltcc_reset((strm), sizeof(deflate_state))
129-
130-
#define DEFLATE_HOOK dfltcc_deflate
131-
132-
#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
133-
134122
#define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
135123

136-
#define INFLATE_RESET_HOOK(strm) \
137-
dfltcc_reset((strm), sizeof(struct inflate_state))
138-
139-
#define INFLATE_TYPEDO_HOOK(strm, flush) \
140-
if (dfltcc_can_inflate((strm))) { \
141-
dfltcc_inflate_action action; \
142-
\
143-
RESTORE(); \
144-
action = dfltcc_inflate((strm), (flush), &ret); \
145-
LOAD(); \
146-
if (action == DFLTCC_INFLATE_CONTINUE) \
147-
break; \
148-
else if (action == DFLTCC_INFLATE_BREAK) \
149-
goto inf_leave; \
150-
}
151-
152-
#define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm)))
153-
154-
#define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm)))
155-
156124
#endif /* DFLTCC_H */

lib/zlib_dfltcc/dfltcc_deflate.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
#include "../zlib_deflate/defutil.h"
44
#include "dfltcc_util.h"
5-
#include "dfltcc.h"
5+
#include "dfltcc_deflate.h"
66
#include <asm/setup.h>
77
#include <linux/export.h>
88
#include <linux/zutil.h>
99

10+
#define GET_DFLTCC_DEFLATE_STATE(state) ((struct dfltcc_deflate_state *)GET_DFLTCC_STATE(state))
11+
1012
/*
1113
* Compress.
1214
*/
@@ -15,7 +17,7 @@ int dfltcc_can_deflate(
1517
)
1618
{
1719
deflate_state *state = (deflate_state *)strm->state;
18-
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
20+
struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
1921

2022
/* Check for kernel dfltcc command line parameter */
2123
if (zlib_dfltcc_support == ZLIB_DFLTCC_DISABLED ||
@@ -28,15 +30,32 @@ int dfltcc_can_deflate(
2830
return 0;
2931

3032
/* Unsupported hardware */
31-
if (!is_bit_set(dfltcc_state->af.fns, DFLTCC_GDHT) ||
32-
!is_bit_set(dfltcc_state->af.fns, DFLTCC_CMPR) ||
33-
!is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0))
33+
if (!is_bit_set(dfltcc_state->common.af.fns, DFLTCC_GDHT) ||
34+
!is_bit_set(dfltcc_state->common.af.fns, DFLTCC_CMPR) ||
35+
!is_bit_set(dfltcc_state->common.af.fmts, DFLTCC_FMT0))
3436
return 0;
3537

3638
return 1;
3739
}
3840
EXPORT_SYMBOL(dfltcc_can_deflate);
3941

42+
void dfltcc_reset_deflate_state(z_streamp strm) {
43+
deflate_state *state = (deflate_state *)strm->state;
44+
struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
45+
46+
dfltcc_reset_state(&dfltcc_state->common);
47+
48+
/* Initialize tuning parameters */
49+
if (zlib_dfltcc_support == ZLIB_DFLTCC_FULL_DEBUG)
50+
dfltcc_state->level_mask = DFLTCC_LEVEL_MASK_DEBUG;
51+
else
52+
dfltcc_state->level_mask = DFLTCC_LEVEL_MASK;
53+
dfltcc_state->block_size = DFLTCC_BLOCK_SIZE;
54+
dfltcc_state->block_threshold = DFLTCC_FIRST_FHT_BLOCK_SIZE;
55+
dfltcc_state->dht_threshold = DFLTCC_DHT_MIN_SAMPLE_SIZE;
56+
}
57+
EXPORT_SYMBOL(dfltcc_reset_deflate_state);
58+
4059
static void dfltcc_gdht(
4160
z_streamp strm
4261
)
@@ -104,8 +123,8 @@ int dfltcc_deflate(
104123
)
105124
{
106125
deflate_state *state = (deflate_state *)strm->state;
107-
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
108-
struct dfltcc_param_v0 *param = &dfltcc_state->param;
126+
struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
127+
struct dfltcc_param_v0 *param = &dfltcc_state->common.param;
109128
uInt masked_avail_in;
110129
dfltcc_cc cc;
111130
int need_empty_block;
@@ -244,7 +263,7 @@ int dfltcc_deflate(
244263
} while (cc == DFLTCC_CC_AGAIN);
245264

246265
/* Translate parameter block to stream */
247-
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
266+
strm->msg = oesc_msg(dfltcc_state->common.msg, param->oesc);
248267
state->bi_valid = param->sbb;
249268
if (state->bi_valid == 0)
250269
state->bi_buf = 0; /* Avoid accessing next_out */

lib/zlib_dfltcc/dfltcc_deflate.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Zlib
2+
#ifndef DFLTCC_DEFLATE_H
3+
#define DFLTCC_DEFLATE_H
4+
5+
#include "dfltcc.h"
6+
7+
/* External functions */
8+
int dfltcc_can_deflate(z_streamp strm);
9+
int dfltcc_deflate(z_streamp strm,
10+
int flush,
11+
block_state *result);
12+
void dfltcc_reset_deflate_state(z_streamp strm);
13+
14+
#define DEFLATE_RESET_HOOK(strm) \
15+
dfltcc_reset_deflate_state((strm))
16+
17+
#define DEFLATE_HOOK dfltcc_deflate
18+
19+
#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
20+
21+
#endif /* DFLTCC_DEFLATE_H */

lib/zlib_dfltcc/dfltcc_inflate.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../zlib_inflate/inflate.h"
44
#include "dfltcc_util.h"
5-
#include "dfltcc.h"
5+
#include "dfltcc_inflate.h"
66
#include <asm/setup.h>
77
#include <linux/export.h>
88
#include <linux/zutil.h>
@@ -32,6 +32,14 @@ int dfltcc_can_inflate(
3232
}
3333
EXPORT_SYMBOL(dfltcc_can_inflate);
3434

35+
void dfltcc_reset_inflate_state(z_streamp strm) {
36+
struct inflate_state *state = (struct inflate_state *)strm->state;
37+
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
38+
39+
dfltcc_reset_state(dfltcc_state);
40+
}
41+
EXPORT_SYMBOL(dfltcc_reset_inflate_state);
42+
3543
static int dfltcc_was_inflate_used(
3644
z_streamp strm
3745
)

lib/zlib_dfltcc/dfltcc_inflate.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: Zlib
2+
#ifndef DFLTCC_INFLATE_H
3+
#define DFLTCC_INFLATE_H
4+
5+
#include "dfltcc.h"
6+
7+
/* External functions */
8+
void dfltcc_reset_inflate_state(z_streamp strm);
9+
int dfltcc_can_inflate(z_streamp strm);
10+
typedef enum {
11+
DFLTCC_INFLATE_CONTINUE,
12+
DFLTCC_INFLATE_BREAK,
13+
DFLTCC_INFLATE_SOFTWARE,
14+
} dfltcc_inflate_action;
15+
dfltcc_inflate_action dfltcc_inflate(z_streamp strm,
16+
int flush, int *ret);
17+
#define INFLATE_RESET_HOOK(strm) \
18+
dfltcc_reset_inflate_state((strm))
19+
20+
#define INFLATE_TYPEDO_HOOK(strm, flush) \
21+
if (dfltcc_can_inflate((strm))) { \
22+
dfltcc_inflate_action action; \
23+
\
24+
RESTORE(); \
25+
action = dfltcc_inflate((strm), (flush), &ret); \
26+
LOAD(); \
27+
if (action == DFLTCC_INFLATE_CONTINUE) \
28+
break; \
29+
else if (action == DFLTCC_INFLATE_BREAK) \
30+
goto inf_leave; \
31+
}
32+
33+
#define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm)))
34+
35+
#define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm)))
36+
37+
#endif /* DFLTCC_DEFLATE_H */

lib/zlib_inflate/inflate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/* architecture-specific bits */
1919
#ifdef CONFIG_ZLIB_DFLTCC
20-
# include "../zlib_dfltcc/dfltcc.h"
20+
# include "../zlib_dfltcc/dfltcc_inflate.h"
2121
#else
2222
#define INFLATE_RESET_HOOK(strm) do {} while (0)
2323
#define INFLATE_TYPEDO_HOOK(strm, flush) do {} while (0)

0 commit comments

Comments
 (0)