Skip to content

Commit

Permalink
Refactor Heuristic polling for Multibuffer support.
Browse files Browse the repository at this point in the history
Refactored and grouped number of items in the queue into asym,
KDF and sym queues to support other algorithms. The Heuristic polling
threshold for the multibuffer case can be configured via nginx.conf
using `qat_heuristic_poll_asym_multibuff_threshold` and
`qat_heuristic_poll_sym_multibuff_threshold`. The default threshold if
not specified is 8.

Signed-off-by: David Qian <[email protected]>
  • Loading branch information
Yogaraj-Alamenda authored and daweiq committed Sep 24, 2020
1 parent cec5e7a commit 7e0c531
Showing 1 changed file with 79 additions and 31 deletions.
110 changes: 79 additions & 31 deletions modules/nginx_qat_module/ngx_ssl_engine_qat_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ typedef struct {

ngx_int_t heuristic_poll_sym_threshold;

ngx_int_t heuristic_poll_asym_multibuff_threshold;

ngx_int_t heuristic_poll_sym_multibuff_threshold;

ngx_array_t *small_pkt_offload_threshold;
} ngx_ssl_engine_qat_conf_t;

Expand Down Expand Up @@ -100,8 +104,9 @@ static void ngx_ssl_engine_qat_process_exit(ngx_cycle_t *cycle);
#define GET_NUM_ASYM_REQUESTS_IN_FLIGHT 1
#define GET_NUM_KDF_REQUESTS_IN_FLIGHT 2
#define GET_NUM_CIPHER_PIPELINE_REQUESTS_IN_FLIGHT 3
#define GET_NUM_ITEMS_RSA_PRIV_QUEUE 4
#define GET_NUM_ITEMS_RSA_PUB_QUEUE 5
#define GET_NUM_ASYM_NUM_ITEMS_IN_QUEUE 4
#define GET_NUM_KDF_NUM_ITEMS_IN_QUEUE 5
#define GET_NUM_SYM_NUM_ITEMS_IN_QUEUE 6

#define INLINE_POLL 1
#define INTERNAL_POLL 2
Expand Down Expand Up @@ -129,6 +134,8 @@ static ngx_uint_t qat_engine_enable_heuristic_polling;
static ngx_event_t qat_engine_heuristic_poll_event;
static ngx_int_t qat_engine_heuristic_poll_asym_threshold;
static ngx_int_t qat_engine_heuristic_poll_sym_threshold;
static ngx_int_t qat_engine_heuristic_poll_asym_multibuff_threshold;
static ngx_int_t qat_engine_heuristic_poll_sym_multibuff_threshold;

/* Since any polling mode change need to restart Nginx service
* The initial polling mode is record when Nginx master start
Expand All @@ -149,8 +156,9 @@ static int num_heuristic_poll = 0;
static int *num_asym_requests_in_flight = NULL;
static int *num_kdf_requests_in_flight = NULL;
static int *num_cipher_requests_in_flight = NULL;
static int *num_items_rsa_priv_queue = NULL;
static int *num_items_rsa_pub_queue = NULL;
static int *num_asym_mb_items_in_queue = NULL;
static int *num_kdf_mb_items_in_queue = NULL;
static int *num_sym_mb_items_in_queue = NULL;

static ngx_str_t ssl_engine_qat_name = ngx_string("qatengine");

Expand Down Expand Up @@ -226,6 +234,20 @@ static ngx_command_t ngx_ssl_engine_qat_commands[] = {
offsetof(ngx_ssl_engine_qat_conf_t, heuristic_poll_sym_threshold),
NULL },

{ ngx_string("qat_heuristic_poll_asym_multibuff_threshold"),
NGX_SSL_ENGINE_SUB_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
0,
offsetof(ngx_ssl_engine_qat_conf_t, heuristic_poll_asym_multibuff_threshold),
NULL },

{ ngx_string("qat_heuristic_poll_sym_multibuff_threshold"),
NGX_SSL_ENGINE_SUB_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
0,
offsetof(ngx_ssl_engine_qat_conf_t, heuristic_poll_sym_multibuff_threshold),
NULL },

{ ngx_string("qat_small_pkt_offload_threshold"),
NGX_SSL_ENGINE_SUB_CONF|NGX_CONF_1MORE,
ngx_ssl_engine_qat_set_threshold,
Expand Down Expand Up @@ -319,8 +341,9 @@ ngx_ssl_engine_qat_release(ngx_cycle_t *cycle)
if(0 == *num_asym_requests_in_flight &&
0 == *num_kdf_requests_in_flight &&
0 == *num_cipher_requests_in_flight &&
0 == *num_items_rsa_priv_queue &&
0 == *num_items_rsa_pub_queue &&
0 == *num_asym_mb_items_in_queue &&
0 == *num_kdf_mb_items_in_queue &&
0 == *num_sym_mb_items_in_queue &&
1 == qat_finish(e)) {
qat_instance_status.finished = 1;
ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0,
Expand Down Expand Up @@ -563,8 +586,8 @@ qat_engine_external_poll_handler(ngx_event_t *ev)
}

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue > 0) {
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue > 0) {
qat_engine_poll(ev->log);
}

Expand Down Expand Up @@ -600,16 +623,16 @@ qat_engine_heuristic_poll_handler(ngx_event_t *ev)
}

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue > 0) {
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue > 0) {
if (num_heuristic_poll == 0) {
qat_engine_poll(ev->log);
}
}

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue> 0) {
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue > 0) {
if (ngx_event_timer_rbtree.root != ngx_event_timer_rbtree.sentinel ||
!ngx_exiting) {
num_heuristic_poll = 0;
Expand Down Expand Up @@ -670,14 +693,15 @@ ngx_ssl_engine_qat_heuristic_poll(ngx_log_t *log) {
int threshold;

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue <= 0)
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue <= 0)
return;

/* one-time try to retrieve QAT responses */
if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue >= (int) *ngx_ssl_active) {
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue
>= (int) *ngx_ssl_active) {
qat_engine_poll(log);
num_heuristic_poll ++;
polled_flag = 1;
Expand All @@ -686,22 +710,25 @@ ngx_ssl_engine_qat_heuristic_poll(ngx_log_t *log) {
if (!polled_flag) {
if (*num_asym_requests_in_flight > 0)
threshold = qat_engine_heuristic_poll_asym_threshold;
else if (*num_items_rsa_priv_queue + *num_items_rsa_pub_queue > 0)
threshold = HEURISTIC_POLL_MULTIBUFF_DEFAULT_THRESHOLD;
else if (*num_asym_mb_items_in_queue > 0)
threshold = qat_engine_heuristic_poll_asym_multibuff_threshold;
else if (*num_sym_mb_items_in_queue > 0)
threshold = qat_engine_heuristic_poll_sym_multibuff_threshold;
else
threshold = qat_engine_heuristic_poll_sym_threshold;

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue >= threshold) {
+ *num_cipher_requests_in_flight + *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue
>= threshold) {
qat_engine_poll(log);
num_heuristic_poll ++;
}
}

if (*num_asym_requests_in_flight + *num_kdf_requests_in_flight
+ *num_cipher_requests_in_flight + *num_items_rsa_priv_queue
+ *num_items_rsa_pub_queue > 0
+ *num_cipher_requests_in_flight+ *num_asym_mb_items_in_queue
+ *num_kdf_mb_items_in_queue + *num_sym_mb_items_in_queue > 0
&& !qat_engine_heuristic_poll_event.timer_set) {
num_heuristic_poll = 0;
ngx_add_timer(&qat_engine_heuristic_poll_event,
Expand Down Expand Up @@ -793,6 +820,8 @@ ngx_ssl_engine_qat_create_conf(ngx_cycle_t *cycle)

seqcf->heuristic_poll_asym_threshold = NGX_CONF_UNSET;
seqcf->heuristic_poll_sym_threshold = NGX_CONF_UNSET;
seqcf->heuristic_poll_asym_multibuff_threshold = NGX_CONF_UNSET;
seqcf->heuristic_poll_sym_multibuff_threshold = NGX_CONF_UNSET;

seqcf->small_pkt_offload_threshold = NGX_CONF_UNSET_PTR;

Expand Down Expand Up @@ -882,6 +911,11 @@ ngx_ssl_engine_qat_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(seqcf->heuristic_poll_sym_threshold,
HEURISTIC_POLL_SYM_DEFAULT_THRESHOLD);

ngx_conf_init_value(seqcf->heuristic_poll_asym_multibuff_threshold,
HEURISTIC_POLL_MULTIBUFF_DEFAULT_THRESHOLD);

ngx_conf_init_value(seqcf->heuristic_poll_sym_multibuff_threshold,
HEURISTIC_POLL_MULTIBUFF_DEFAULT_THRESHOLD);

/* check the validity of the conf vaules */

Expand Down Expand Up @@ -964,7 +998,9 @@ ngx_ssl_engine_qat_init_conf(ngx_cycle_t *cycle, void *conf)
}

if (seqcf->heuristic_poll_asym_threshold > 512
|| seqcf->heuristic_poll_sym_threshold > 512) {
|| seqcf->heuristic_poll_sym_threshold > 512
|| seqcf->heuristic_poll_asym_multibuff_threshold > 512
|| seqcf->heuristic_poll_sym_multibuff_threshold > 512 ) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"invalid heuristic poll threshold");
return NGX_CONF_ERROR;
Expand Down Expand Up @@ -1002,6 +1038,12 @@ ngx_ssl_engine_qat_init_conf(ngx_cycle_t *cycle, void *conf)
qat_engine_heuristic_poll_sym_threshold
= seqcf->heuristic_poll_sym_threshold;

qat_engine_heuristic_poll_asym_multibuff_threshold
= seqcf->heuristic_poll_asym_multibuff_threshold;

qat_engine_heuristic_poll_sym_multibuff_threshold
= seqcf->heuristic_poll_sym_multibuff_threshold;

return NGX_CONF_OK;
}

Expand Down Expand Up @@ -1032,21 +1074,26 @@ qat_engine_share_info(ngx_log_t *log) {
return NGX_ERROR;
}
if (!ENGINE_ctrl_cmd(qat_engine, "GET_NUM_REQUESTS_IN_FLIGHT",
GET_NUM_ITEMS_RSA_PRIV_QUEUE,
&num_items_rsa_priv_queue, NULL, 0)) {
GET_NUM_ASYM_NUM_ITEMS_IN_QUEUE,
&num_asym_mb_items_in_queue, NULL, 0)) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"QAT Engine failed: GET_NUM_REQUESTS_IN_FLIGHT");
return NGX_ERROR;
}
if (!ENGINE_ctrl_cmd(qat_engine, "GET_NUM_REQUESTS_IN_FLIGHT",
GET_NUM_ITEMS_RSA_PUB_QUEUE,
&num_items_rsa_pub_queue, NULL, 0)) {
GET_NUM_KDF_NUM_ITEMS_IN_QUEUE,
&num_kdf_mb_items_in_queue, NULL, 0)) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"QAT Engine failed: GET_NUM_REQUESTS_IN_FLIGHT");
return NGX_ERROR;
}
if (!ENGINE_ctrl_cmd(qat_engine, "GET_NUM_REQUESTS_IN_FLIGHT",
GET_NUM_SYM_NUM_ITEMS_IN_QUEUE,
&num_sym_mb_items_in_queue, NULL, 0)) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"QAT Engine failed: GET_NUM_REQUESTS_IN_FLIGHT");
return NGX_ERROR;
}



return NGX_OK;
}
Expand All @@ -1059,8 +1106,9 @@ ngx_ssl_engine_qat_process_init(ngx_cycle_t *cycle)
num_asym_requests_in_flight = NULL;
num_kdf_requests_in_flight = NULL;
num_cipher_requests_in_flight = NULL;
num_items_rsa_priv_queue = NULL;
num_items_rsa_pub_queue = NULL;
num_asym_mb_items_in_queue = NULL;
num_kdf_mb_items_in_queue = NULL;
num_sym_mb_items_in_queue = NULL;

qat_engine = ENGINE_by_id((const char *) ssl_engine_qat_name.data);
if (qat_engine == NULL) {
Expand Down

0 comments on commit 7e0c531

Please sign in to comment.