Browse Source

Move CSA benchmark from tsdecrypt.c to csa.c

Georgi Chorbadzhiyski 12 years ago
parent
commit
2787b678b0
4 changed files with 98 additions and 47 deletions
  1. 1
    0
      Makefile
  2. 72
    0
      csa.c
  3. 23
    0
      csa.h
  4. 2
    47
      tsdecrypt.c

+ 1
- 0
Makefile View File

@@ -36,6 +36,7 @@ TS_DIR = libtsfuncs
36 36
 TS_LIB = $(TS_DIR)/libtsfuncs.a
37 37
 
38 38
 tsdecrypt_SRC = data.c \
39
+ csa.c \
39 40
  udp.c \
40 41
  util.c \
41 42
  camd.c \

+ 72
- 0
csa.c View File

@@ -0,0 +1,72 @@
1
+/*
2
+ * CSA functions
3
+ * Copyright (C) 2011-2012 Unix Solutions Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License version 2
7
+ * as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+ * GNU General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
+ */
18
+
19
+#include <stdio.h>
20
+#include <stdlib.h>
21
+#include <string.h>
22
+#include <inttypes.h>
23
+#include <sys/time.h>
24
+
25
+#include <dvbcsa/dvbcsa.h>
26
+
27
+#include "libfuncs/libfuncs.h"
28
+
29
+/* The following routine is taken from benchbitslice in libdvbcsa */
30
+void csa_benchmark(void) {
31
+	struct timeval t0, t1;
32
+	struct dvbcsa_bs_key_s *key = dvbcsa_bs_key_alloc();
33
+	unsigned int n, i, npackets = 0;
34
+	unsigned int batch_size = dvbcsa_bs_batch_size();
35
+	uint8_t data[batch_size + 1][188];
36
+	struct dvbcsa_bs_batch_s pcks[batch_size + 1];
37
+	uint8_t cw[8] = { 0x12, 0x34, 0x56, 0x78, 0x89, 0xab, 0xcd, 0xef, };
38
+
39
+	srand(time(0));
40
+	puts("Single threaded CSA decoding benchmark");
41
+
42
+	dvbcsa_bs_key_set (cw, key);
43
+
44
+	printf("Batch size %d packets.\n\n", batch_size);
45
+	for (i = 0; i < batch_size; i++) {
46
+		pcks[i].data = data[i];
47
+		pcks[i].len = 184;
48
+		memset(data[i], rand(), pcks[i].len);
49
+	}
50
+	pcks[i].data = NULL;
51
+
52
+	gettimeofday(&t0, NULL);
53
+	for (n = (1 << 12) / batch_size; n < (1 << 19) / batch_size; n *= 2) {
54
+		printf(" Decrypting %6u mpegts packets\r", n * batch_size);
55
+		fflush(stdout);
56
+		for (i = 0; i < n; i++) {
57
+			dvbcsa_bs_decrypt(key, pcks, 184);
58
+		}
59
+		npackets += n * batch_size;
60
+	}
61
+	gettimeofday(&t1, NULL);
62
+
63
+	unsigned long long usec = timeval_diff_usec(&t0, &t1);
64
+	printf("DONE: %u packets (%u bytes) decrypted in %llu ms = %.1f Mbits/s\n\n",
65
+		npackets,
66
+		npackets * 188,
67
+		usec / 1000,
68
+		(double)(npackets * 188 * 8) / (double)usec
69
+	);
70
+
71
+	dvbcsa_bs_key_free(key);
72
+}

+ 23
- 0
csa.h View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * CSA functions
3
+ * Copyright (C) 2012 Unix Solutions Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License version 2
7
+ * as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+ * GNU General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
+ */
18
+#ifndef CSA_H
19
+#define CSA_H
20
+
21
+void csa_benchmark(void);
22
+
23
+#endif

+ 2
- 47
tsdecrypt.c View File

@@ -27,13 +27,13 @@
27 27
 #include <syslog.h>
28 28
 #include <sys/resource.h>
29 29
 
30
-#include <dvbcsa/dvbcsa.h>
31 30
 #include <openssl/rand.h>
32 31
 
33 32
 #include "libfuncs/libfuncs.h"
34 33
 
35 34
 #include "data.h"
36 35
 #include "util.h"
36
+#include "csa.h"
37 37
 #include "camd.h"
38 38
 #include "process.h"
39 39
 #include "udp.h"
@@ -69,51 +69,6 @@ static void LOG_func(const char *msg) {
69 69
 		LOG(msg);
70 70
 }
71 71
 
72
-/* The following routine is taken from benchbitslice in libdvbcsa */
73
-void run_benchmark(void) {
74
-	struct timeval t0, t1;
75
-	struct dvbcsa_bs_key_s *ffkey = dvbcsa_bs_key_alloc();
76
-	unsigned int n, i, c = 0, pkt_len = 0;
77
-	unsigned int gs = dvbcsa_bs_batch_size();
78
-	uint8_t data[gs + 1][184];
79
-	struct dvbcsa_bs_batch_s pcks[gs + 1];
80
-	uint8_t cw[8] = { 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, };
81
-
82
-	srand(time(0));
83
-
84
-	puts("* Single threaded libdvbcsa benchmark *");
85
-
86
-	dvbcsa_bs_key_set (cw, ffkey);
87
-
88
-	printf(" - Generating batch with %i randomly sized packets\n\n", gs);
89
-	for (i = 0; i < gs; i++) {
90
-		pcks[i].data = data[i];
91
-		pcks[i].len = 100 + rand() % 85;
92
-		memset(data[i], rand(), pcks[i].len);
93
-		pkt_len += pcks[i].len;
94
-	}
95
-	pcks[i].data = NULL;
96
-
97
-	gettimeofday(&t0, NULL);
98
-	for (n = (1 << 12) / gs; n < (1 << 19) / gs; n *= 2) {
99
-		printf(" - Decrypting %u TS packets\n", n * gs);
100
-		for (i = 0; i < n; i++) {
101
-			dvbcsa_bs_decrypt(ffkey, pcks, 184);
102
-		}
103
-		c += n * gs;
104
-	}
105
-	gettimeofday(&t1, NULL);
106
-
107
-	printf("\n* %u packets proceded: %.1f Mbits/s\n\n", c,
108
-		(float)(c * 188 * 8) / (float)timeval_diff_usec(&t0, &t1)
109
-		/*(float)((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec)) */
110
-	);
111
-
112
-	dvbcsa_bs_key_free(ffkey);
113
-
114
-	puts("* Done *");
115
-}
116
-
117 72
 static const char short_options[] = "i:d:N:Sl:L:F:I:RzM:T:W:O:o:t:rk:g:pwxyc:C:Y:A:s:U:P:B:eZ:Ef:X:H:G:KJ:D:jbhV";
118 73
 
119 74
 // Unused short options: Qamnquv0123456789
@@ -497,7 +452,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
497 452
 				ts->pid_report = 1;
498 453
 				break;
499 454
 			case 'b': // --bench
500
-				run_benchmark();
455
+				csa_benchmark();
501 456
 				exit(EXIT_SUCCESS);
502 457
 
503 458
 			case 'h': // --help

Loading…
Cancel
Save