Skip to content

Commit 7520429

Browse files
committed
Merge branch 'master' into update_to_manylinux_2_28
2 parents b0e205a + a2d930b commit 7520429

File tree

5 files changed

+102
-10
lines changed

5 files changed

+102
-10
lines changed

.github/workflows/build-wheels.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
- name: Ubuntu 24.04
2424
runs-on: ubuntu-latest
2525
matrix: linux
26-
- name: Ubuntu 20.04
27-
runs-on: ubuntu-20
28-
matrix: linux
2926
- name: Windows
3027
runs-on: windows-latest
3128
matrix: windows

src/python-zstd.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ static PyObject *py_zstd_threads_count(PyObject* self, PyObject *args)
455455
return Py_BuildValue("i", threads);
456456
}
457457

458+
static PyObject *py_zstd_set_cpu_cores_cache_ttl(PyObject* self, PyObject *args)
459+
{
460+
UNUSED(self);
461+
462+
int32_t cacheTTL = 0;
463+
464+
#if PY_MAJOR_VERSION >= 3
465+
if (!PyArg_ParseTuple(args, "i", &cacheTTL))
466+
return NULL;
467+
#else
468+
if (!PyArg_ParseTuple(args, "i", &cacheTTL))
469+
return NULL;
470+
#endif
471+
if (cacheTTL==0) cacheTTL=60;
472+
473+
UTIL_setCpuCoresCacheTTL(cacheTTL);
474+
return Py_BuildValue("i", 0);
475+
}
476+
458477
/**
459478
* Returns ZSTD determined max threads count, int
460479
*/
@@ -533,7 +552,9 @@ static PyMethodDef ZstdMethods[] = {
533552
{"ZSTD_is_debug_notice_enabled", py_zstd_is_debug_notice_enabled, METH_NOARGS, NULL},
534553
{"ZSTD_is_debug_info_enabled", py_zstd_is_debug_info_enabled, METH_NOARGS, NULL},
535554
{"ZSTD_is_debug_error_enabled", py_zstd_is_debug_error_enabled, METH_NOARGS, NULL},
536-
555+
556+
{"ZSTD_setCpuCoresCacheTTL", py_zstd_set_cpu_cores_cache_ttl,METH_VARARGS, NULL},
557+
537558
{NULL, NULL, 0, NULL}
538559
};
539560

src/util.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ int UTIL_countAvailableCores(void)
156156
static int numLogicalCores = 0;
157157
static time_t lastTimeCached = 0;
158158
time_t currTime = time(NULL);
159-
int cachettl = 60;
160-
if (lastTimeCached && currTime-lastTimeCached>cachettl) numLogicalCores = 0;
159+
// int cachettl = 60;
160+
if (lastTimeCached && currTime-lastTimeCached>/*cachettl*/util_cpuCoresCacheTTL) numLogicalCores = 0;
161161

162162
if (numLogicalCores != 0) {
163163
printdn("Stored static numLogicalCores: %d\n", numLogicalCores);
@@ -260,8 +260,8 @@ int UTIL_countAvailableCores(void)
260260
static int numLogicalCores = 0; /* freebsd sysctl is native int sized */
261261
static time_t lastTimeCached = 0;
262262
time_t currTime = time(NULL);
263-
int cachettl = 60;
264-
if (lastTimeCached && currTime-lastTimeCached>cachettl) numLogicalCores = 0;
263+
// int cachettl = 60;
264+
if (lastTimeCached && currTime-lastTimeCached>/*cachettl*/util_cpuCoresCacheTTL) numLogicalCores = 0;
265265

266266
if (numLogicalCores != 0) return numLogicalCores;
267267

@@ -295,8 +295,8 @@ int UTIL_countAvailableCores(void)
295295
static int numLogicalCores = 0;
296296
static time_t lastTimeCached = 0;
297297
time_t currTime = time(NULL);
298-
int cachettl = 60;
299-
if (lastTimeCached && currTime-lastTimeCached>cachettl) numLogicalCores = 0;
298+
// int cachettl = 60;
299+
if (lastTimeCached && currTime-lastTimeCached>/*cachettl*/util_cpuCoresCacheTTL) numLogicalCores = 0;
300300

301301
if (numLogicalCores != 0) return numLogicalCores;
302302

@@ -319,6 +319,11 @@ int UTIL_countAvailableCores(void)
319319

320320
#endif
321321

322+
int UTIL_setCpuCoresCacheTTL(int cacheTTL){
323+
util_cpuCoresCacheTTL = cacheTTL;
324+
return 0;
325+
}
326+
322327
#if defined (__cplusplus)
323328
}
324329
#endif

src/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ extern "C" {
6666
typedef struct stat stat_t;
6767
#endif
6868

69+
static int util_cpuCoresCacheTTL = 60;
6970
int UTIL_countAvailableCores(void);
71+
int UTIL_setCpuCoresCacheTTL(int cacheTTL);
7072

7173
#if defined (__cplusplus)
7274
}

tests/test_speed.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,73 @@ def test_check_speed(self):
9898
log.info("end Check memory usage = %6.2f kb" % (1.0*endMemoryUsage/1024,))
9999
log.info("Check speed average = %6.2f Mb/sec" % (1.0*sum/1024/1024/wait,))
100100
log.info("diff Check memory usage = %6.2f kb" % (1.0*(endMemoryUsage-beginMemoryUsage)/1024,))
101+
102+
def test_cpu_cores_cache_60_speed(self):
103+
wait = 70
104+
log.info("\nWait %d seconds..." % wait)
105+
ops = 0
106+
tbegin = time()
107+
beginMemoryUsage=get_real_memory_usage()
108+
log.info("begin Check memory usage= %6.2f kb" % (1.0*beginMemoryUsage/1024,))
109+
while time()-tbegin<wait:
110+
cores = zstd.ZSTD_threads_count()
111+
ops+=1
112+
113+
endMemoryUsage=get_real_memory_usage()
114+
log.info("end Check memory usage = %6.2f kb" % (1.0*endMemoryUsage/1024,))
115+
log.info("Check cache use speed(60) average = %6.2f Ops/sec" % (1.0*ops/wait,))
116+
log.info("diff Check memory usage = %6.2f kb" % (1.0*(endMemoryUsage-beginMemoryUsage)/1024,))
117+
118+
def test_cpu_cores_cache_01_speed(self):
119+
wait = 70
120+
log.info("\nWait %d seconds..." % wait)
121+
ops = 0
122+
tbegin = time()
123+
beginMemoryUsage=get_real_memory_usage()
124+
zstd.ZSTD_setCpuCoresCacheTTL(1)
125+
log.info("begin Check memory usage= %6.2f kb" % (1.0*beginMemoryUsage/1024,))
126+
while time()-tbegin<wait:
127+
cores = zstd.ZSTD_threads_count()
128+
ops+=1
129+
130+
endMemoryUsage=get_real_memory_usage()
131+
log.info("end Check memory usage = %6.2f kb" % (1.0*endMemoryUsage/1024,))
132+
log.info("Check cache use speed(1) average = %6.2f Ops/sec" % (1.0*ops/wait,))
133+
log.info("diff Check memory usage = %6.2f kb" % (1.0*(endMemoryUsage-beginMemoryUsage)/1024,))
134+
135+
def test_cpu_cores_cache_05_speed(self):
136+
wait = 70
137+
log.info("\nWait %d seconds..." % wait)
138+
ops = 0
139+
tbegin = time()
140+
beginMemoryUsage=get_real_memory_usage()
141+
zstd.ZSTD_setCpuCoresCacheTTL(5)
142+
log.info("begin Check memory usage= %6.2f kb" % (1.0*beginMemoryUsage/1024,))
143+
while time()-tbegin<wait:
144+
cores = zstd.ZSTD_threads_count()
145+
ops+=1
146+
147+
endMemoryUsage=get_real_memory_usage()
148+
log.info("end Check memory usage = %6.2f kb" % (1.0*endMemoryUsage/1024,))
149+
log.info("Check cache use speed(5) average = %6.2f Ops/sec" % (1.0*ops/wait,))
150+
log.info("diff Check memory usage = %6.2f kb" % (1.0*(endMemoryUsage-beginMemoryUsage)/1024,))
151+
152+
def test_cpu_cores_cache_10_speed(self):
153+
wait = 70
154+
log.info("\nWait %d seconds..." % wait)
155+
ops = 0
156+
tbegin = time()
157+
beginMemoryUsage=get_real_memory_usage()
158+
zstd.ZSTD_setCpuCoresCacheTTL(10)
159+
log.info("begin Check memory usage= %6.2f kb" % (1.0*beginMemoryUsage/1024,))
160+
while time()-tbegin<wait:
161+
cores = zstd.ZSTD_threads_count()
162+
ops+=1
163+
164+
endMemoryUsage=get_real_memory_usage()
165+
log.info("end Check memory usage = %6.2f kb" % (1.0*endMemoryUsage/1024,))
166+
log.info("Check cache use speed(10) average = %6.2f Ops/sec" % (1.0*ops/wait,))
167+
log.info("diff Check memory usage = %6.2f kb" % (1.0*(endMemoryUsage-beginMemoryUsage)/1024,))
101168

102169
if __name__ == '__main__':
103170
unittest.main()

0 commit comments

Comments
 (0)