5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2007 - 2008 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #include "silccrypto.h"
22 #include "softacc_i.h"
24 /* Software accelerator is a thread-pool system where computationally
25 expensive operations are executed in multiple threads for the purpose of
26 off-loading and balancing the computations across multiple processors. */
28 /************************** Types and definitions ***************************/
30 /* Software accelerator operations */
31 const SilcAcceleratorStruct silc_softacc =
33 "softacc", silc_softacc_init, silc_softacc_uninit,
34 #ifdef SILC_DIST_SOFTACC_PKCS
36 #else /* !SILC_DIST_SOFTACC_PKCS */
38 #endif /* SILC_DIST_SOFTACC_PKCS */
39 #ifdef SILC_DIST_SOFTACC_CIPHER
41 #else /* !SILC_DIST_SOFTACC_CIPHER */
43 #endif /* SILC_DIST_SOFTACC_CIPHER */
46 /***************************** Accelerator API ******************************/
48 /* Initialize software accelerator */
50 SilcBool silc_softacc_init(SilcSchedule schedule, va_list va)
55 /* If already initialized, uninitialize first. */
56 sa = silc_global_get_var("softacc", FALSE);
58 silc_softacc_uninit();
60 sa = silc_global_set_var("softacc", sizeof(*sa), NULL, FALSE);
64 sa->schedule = schedule;
65 sa->min_threads = SILC_SOFTACC_MIN_THREADS;
66 sa->max_threads = SILC_SOFTACC_MAX_THREADS;
67 sa->cipher_threads = SILC_SOFTACC_CIPHER_THREADS;
68 sa->cipher_blocks = SILC_SOFTACC_CIPHER_BLOCKS;
69 sa->cipher_streams = SILC_SOFTACC_CIPHER_STREAMS;
72 while ((opt = va_arg(va, char *))) {
73 if (!strcmp(opt, "min_threads"))
74 sa->min_threads = va_arg(va, SilcUInt32);
75 else if (!strcmp(opt, "max_threads"))
76 sa->max_threads = va_arg(va, SilcUInt32);
77 else if (!strcmp(opt, "cipher_threads"))
78 sa->cipher_threads = va_arg(va, SilcUInt32);
79 else if (!strcmp(opt, "cipher_blocks"))
80 sa->cipher_blocks = va_arg(va, SilcUInt32);
81 else if (!strcmp(opt, "cipher_streams"))
82 sa->cipher_streams = va_arg(va, SilcUInt32);
85 if (!sa->cipher_streams || !sa->cipher_blocks || !sa->cipher_threads)
88 SILC_LOG_DEBUG(("Initialize software accelerator, min_threads %d, "
89 "max_threads %d", sa->min_threads, sa->max_threads));
91 /* Start the thread pool */
92 sa->tp = silc_thread_pool_alloc(NULL, sa->min_threads,
93 sa->max_threads, TRUE);
95 silc_global_del_var("softacc", FALSE);
104 SilcBool silc_softacc_uninit(void)
108 sa = silc_global_get_var("softacc", FALSE);
112 SILC_LOG_DEBUG(("Uninitialize software accelerator"));
114 silc_thread_pool_free(sa->tp, TRUE);
115 silc_global_del_var("softacc", FALSE);