Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory #216

Merged
merged 20 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/flow_tracker/flow_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ main(int argc, char *argv[]) {
onvm_nflib_run(nf_local_ctx);

onvm_nflib_stop(nf_local_ctx);
onvm_ft_free(state_info->ft);
rte_free(state_info);
printf("If we reach here, program is ending!\n");
return 0;
}
2 changes: 2 additions & 0 deletions examples/load_balancer/load_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ main(int argc, char *argv[]) {
onvm_nflib_run(nf_local_ctx);

onvm_nflib_stop(nf_local_ctx);
onvm_ft_free(lb->ft);
rte_free(lb);
printf("If we reach here, program is ending\n");
return 0;
}
13 changes: 7 additions & 6 deletions onvm/lib/cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <rte_memcpy.h>

#ifdef ENABLE_LOCALES
#include <locale.h>
Expand Down Expand Up @@ -172,7 +173,7 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h
{
return NULL;
}
memcpy(copy, string, length);
rte_memcpy(copy, string, length);

return copy;
}
Expand Down Expand Up @@ -457,7 +458,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
}
if (newbuffer)
{
memcpy(newbuffer, p->buffer, p->offset + 1);
rte_memcpy(newbuffer, p->buffer, p->offset + 1);
}
p->hooks.deallocate(p->buffer);
}
Expand Down Expand Up @@ -897,7 +898,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe
if (escape_characters == 0)
{
output[0] = '\"';
memcpy(output + 1, input, output_length);
rte_memcpy(output + 1, input, output_length);
output[output_length + 1] = '\"';
output[output_length + 2] = '\0';

Expand Down Expand Up @@ -1135,7 +1136,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
{
goto fail;
}
memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
rte_memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
printed[buffer->offset] = '\0'; /* just to be sure */

/* free the buffer */
Expand Down Expand Up @@ -1329,7 +1330,7 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
{
return false;
}
memcpy(output, item->valuestring, raw_length);
rte_memcpy(output, item->valuestring, raw_length);
return true;
}

Expand Down Expand Up @@ -1848,7 +1849,7 @@ static cJSON *create_reference(const cJSON *item, const internal_hooks * const h
return NULL;
}

memcpy(reference, item, sizeof(cJSON));
rte_memcpy(reference, item, sizeof(cJSON));
reference->string = NULL;
reference->type |= cJSON_IsReference;
reference->next = reference->prev = NULL;
Expand Down
28 changes: 14 additions & 14 deletions onvm/onvm_mgr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ rx_thread_main(void *arg) {

RTE_LOG(INFO, APP, "Core %d: RX thread done\n", rte_lcore_id());

free(rx_mgr->nf_rx_bufs);
free(rx_mgr);
rte_free(rx_mgr->nf_rx_bufs);
rte_free(rx_mgr);
return 0;
}

Expand Down Expand Up @@ -255,10 +255,10 @@ tx_thread_main(void *arg) {

RTE_LOG(INFO, APP, "Core %d: TX thread done\n", rte_lcore_id());

free(tx_mgr->tx_thread_info->port_tx_bufs);
free(tx_mgr->tx_thread_info);
free(tx_mgr->nf_rx_bufs);
free(tx_mgr);
rte_free(tx_mgr->tx_thread_info->port_tx_bufs);
rte_free(tx_mgr->tx_thread_info);
rte_free(tx_mgr->nf_rx_bufs);
rte_free(tx_mgr);
return 0;
}

Expand Down Expand Up @@ -306,7 +306,7 @@ wakeup_thread_main(void *arg) {
}
}

free(wakeup_ctx);
rte_free(wakeup_ctx);
return 0;
}

Expand Down Expand Up @@ -374,12 +374,12 @@ main(int argc, char *argv[]) {
signal(SIGTERM, handle_signal);

for (i = 0; i < tx_lcores; i++) {
struct queue_mgr *tx_mgr = calloc(1, sizeof(struct queue_mgr));
struct queue_mgr *tx_mgr = rte_calloc(NULL, 1, sizeof(struct queue_mgr), 0);
tx_mgr->mgr_type_t = MGR;
tx_mgr->id = i;
tx_mgr->tx_thread_info = calloc(1, sizeof(struct tx_thread_info));
tx_mgr->tx_thread_info->port_tx_bufs = calloc(RTE_MAX_ETHPORTS, sizeof(struct packet_buf));
tx_mgr->nf_rx_bufs = calloc(MAX_NFS, sizeof(struct packet_buf));
tx_mgr->tx_thread_info = rte_calloc(NULL, 1, sizeof(struct tx_thread_info), 0);
tx_mgr->tx_thread_info->port_tx_bufs = rte_calloc(NULL, RTE_MAX_ETHPORTS, sizeof(struct packet_buf), 0);
tx_mgr->nf_rx_bufs = rte_calloc(NULL, MAX_NFS, sizeof(struct packet_buf), 0);
tx_mgr->tx_thread_info->first_nf = RTE_MIN(i * nfs_per_tx + 1, (unsigned)MAX_NFS);
tx_mgr->tx_thread_info->last_nf = RTE_MIN((i + 1) * nfs_per_tx + 1, (unsigned)MAX_NFS);
cur_lcore = rte_get_next_lcore(cur_lcore, 1, 1);
Expand All @@ -392,11 +392,11 @@ main(int argc, char *argv[]) {

/* Launch RX thread main function for each RX queue on cores */
for (i = 0; i < rx_lcores; i++) {
struct queue_mgr *rx_mgr = calloc(1, sizeof(struct queue_mgr));
struct queue_mgr *rx_mgr = rte_calloc(NULL, 1, sizeof(struct queue_mgr), 0);
rx_mgr->mgr_type_t = MGR;
rx_mgr->id = i;
rx_mgr->tx_thread_info = NULL;
rx_mgr->nf_rx_bufs = calloc(MAX_NFS, sizeof(struct packet_buf));
rx_mgr->nf_rx_bufs = rte_calloc(NULL, MAX_NFS, sizeof(struct packet_buf), 0);
cur_lcore = rte_get_next_lcore(cur_lcore, 1, 1);
if (rte_eal_remote_launch(rx_thread_main, (void *)rx_mgr, cur_lcore) == -EBUSY) {
RTE_LOG(ERR, APP, "Core %d is already busy, can't use for RX queue id %d\n", cur_lcore,
Expand All @@ -408,7 +408,7 @@ main(int argc, char *argv[]) {
if (ONVM_NF_SHARE_CORES) {
nfs_per_wakeup_thread = ceil((unsigned)MAX_NFS / wakeup_lcores);
for (i = 0; i < ONVM_NUM_WAKEUP_THREADS; i++) {
struct wakeup_thread_context *wakeup_ctx = calloc(1, sizeof(struct wakeup_thread_context));
struct wakeup_thread_context *wakeup_ctx = rte_calloc(NULL, 1, sizeof(struct wakeup_thread_context), 0);
if (wakeup_ctx == NULL) {
RTE_LOG(ERR, APP, "Can't allocate wakeup info struct\n");
return -1;
Expand Down
6 changes: 4 additions & 2 deletions onvm/onvm_mgr/onvm_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void
onvm_stats_gen_event_info(const char *msg, uint8_t type, void *data) {
struct onvm_event *event;

event = (struct onvm_event *)malloc(sizeof(struct onvm_event));
event = (struct onvm_event *)rte_malloc("onvm stats gen event info", sizeof(struct onvm_event), 0);
if (event == NULL) {
perror("Couldn't allocate event");
return;
Expand All @@ -246,7 +246,7 @@ void
onvm_stats_gen_event_nf_info(const char *msg, struct onvm_nf *nf) {
struct onvm_event *event;

event = (struct onvm_event *)malloc(sizeof(struct onvm_event));
event = (struct onvm_event *)rte_malloc("onvm stats gen event nf info", sizeof(struct onvm_event), 0);
if (event == NULL) {
perror("Couldn't allocate event");
return;
Expand All @@ -264,6 +264,7 @@ onvm_stats_gen_event_nf_info(const char *msg, struct onvm_nf *nf) {
static void
onvm_stats_add_event(struct onvm_event *event_info) {
if (event_info == NULL || stats_destination != ONVM_STATS_WEB) {
rte_free(event_info);
return;
}
char event_time_buf[20];
Expand Down Expand Up @@ -305,6 +306,7 @@ onvm_stats_add_event(struct onvm_event *event_info) {

cJSON_AddItemToObject(new_event, "source", source);
cJSON_AddItemToArray(onvm_json_events_arr, new_event);
rte_free(event_info);
}

static void
Expand Down
48 changes: 45 additions & 3 deletions onvm/onvm_nflib/onvm_config_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rte_memcpy.h>

#include "cJSON.h"
#include "onvm_config_common.h"
Expand Down Expand Up @@ -72,6 +73,11 @@ onvm_config_parse_file(const char* filename) {
rewind(fp);

json_str = (char*)malloc(file_length + 1);
if (!json_str) {
printf("Unable to allocate space for json_str\n");
fclose(fp);
return NULL;
}
tmp = json_str;

while ((line = fgets(temp_buf, file_length, fp)) != NULL) {
Expand Down Expand Up @@ -103,9 +109,13 @@ onvm_config_extract_corelist(cJSON* dpdk_config, int* size, int** list) {
}

local_size = cJSON_GetArraySize(json_arr);
if (*list == NULL) {
return -1;
}

local_list = (int*)malloc(*size * sizeof(int));
if (*list == NULL) {
if (local_list == NULL) {
free(*list);
return -1;
}

Expand Down Expand Up @@ -171,6 +181,7 @@ onvm_config_extract_output_location(cJSON* onvm_config, char** output_loc) {
local_output_loc =
(char*)malloc(sizeof(char) * strlen(cJSON_GetObjectItem(onvm_config, "output")->valuestring));
if (local_output_loc == NULL) {
printf("Unable to allocate local output loc");
return -1;
}

Expand Down Expand Up @@ -287,6 +298,7 @@ onvm_config_create_nf_arg_list(cJSON* config, int* argc, char** argv[]) {

new_argv[0] = (char*)malloc(strlen((*argv)[0]));
if (new_argv[0] == NULL) {
free(new_argv);
return -1;
}

Expand Down Expand Up @@ -345,7 +357,7 @@ onvm_config_create_nf_arg_list(cJSON* config, int* argc, char** argv[]) {
for (i = 1; i < onvm_new_argv_index - 1; ++i) {
for (j = 3; j < onvm_old_argv_index - 1; ++j) {
if (strncmp((*argv)[j], new_argv[i], strlen(new_argv[i])) == 0 && j % 2 == 1) {
memcpy(new_argv[i + 1], (*argv)[j + 1], strlen((*argv)[j + 1]));
rte_memcpy(new_argv[i + 1], (*argv)[j + 1], strlen((*argv)[j + 1]));
}
}
}
Expand All @@ -354,7 +366,7 @@ onvm_config_create_nf_arg_list(cJSON* config, int* argc, char** argv[]) {
for (i = onvm_new_argv_index; i < nf_new_argv_index; ++i) {
for (j = onvm_old_argv_index; j < nf_old_argv_index; ++j) {
if (strncmp((*argv)[j], new_argv[i], strlen(new_argv[i])) == 0 && j % 2 == 0) {
memcpy(new_argv[i + 1], (*argv)[j + 1], strlen((*argv)[j + 1]));
rte_memcpy(new_argv[i + 1], (*argv)[j + 1], strlen((*argv)[j + 1]));
}
}
}
Expand Down Expand Up @@ -404,12 +416,15 @@ onvm_config_create_onvm_args(cJSON* onvm_config, int* onvm_argc, char** onvm_arg
service_id_string = (char*)malloc(sizeof(char) * MAX_SERVICE_ID_SIZE);
if (service_id_string == NULL) {
printf("Unable to allocate space for onvm_service_id_string\n");
free(*onvm_argv);
return -1;
}

(*onvm_argv)[0] = malloc(sizeof(char) * strlen(FLAG_R));
if ((*onvm_argv)[0] == NULL) {
printf("Unable to allocate space for onvm_argv[0]\n");
free(service_id_string);
free(*onvm_argv);
return -1;
}

Expand All @@ -422,12 +437,19 @@ onvm_config_create_onvm_args(cJSON* onvm_config, int* onvm_argc, char** onvm_arg
instance_id_string = (char*)malloc(sizeof(char) * MAX_SERVICE_ID_SIZE);
if (instance_id_string == NULL) {
printf("Unable to allocate space for onvm_instance_id_string\n");
free(service_id_string);
free(*onvm_argv);
free((*onvm_argv)[0]);
return -1;
}

(*onvm_argv)[2] = malloc(sizeof(char) * strlen(FLAG_N));
if ((*onvm_argv)[2] == NULL) {
printf("Could not allocate space for instance id in argv\n");
free(instance_id_string);
free(service_id_string);
free(*onvm_argv);
free((*onvm_argv)[0]);
return -1;
}
strncpy((*onvm_argv)[2], FLAG_N, strlen(FLAG_N));
Expand Down Expand Up @@ -464,12 +486,16 @@ onvm_config_create_dpdk_args(cJSON* dpdk_config, int* dpdk_argc, char** dpdk_arg

arg_size = (size_t*)malloc(sizeof(size_t) * (*dpdk_argc));
if (arg_size == NULL) {
printf("Unable to allocate space for arg size\n");
free(*dpdk_argv);
return -1;
}

core_string = (char*)malloc(sizeof(char) * strlen(cJSON_GetObjectItem(dpdk_config, "corelist")->valuestring));
if (core_string == NULL) {
printf("Unable to allocate space for core string\n");
free(*dpdk_argv);
free(arg_size);
return -1;
}

Expand All @@ -478,13 +504,19 @@ onvm_config_create_dpdk_args(cJSON* dpdk_config, int* dpdk_argc, char** dpdk_arg

if (onvm_config_extract_memory_channels(dpdk_config, &mem_channels) < 0) {
printf("Unable to extract memory channels\n");
free(*dpdk_argv);
free(core_string);
free(arg_size);
return -1;
}

mem_channels_string_size = sizeof(char) * 3;
mem_channels_string = (char*)malloc(mem_channels_string_size);
if (mem_channels_string == NULL) {
printf("Unable to allocate space for memory channels string\n");
free(*dpdk_argv);
free(core_string);
free(arg_size);
return -1;
}

Expand All @@ -501,6 +533,16 @@ onvm_config_create_dpdk_args(cJSON* dpdk_config, int* dpdk_argc, char** dpdk_arg
(*dpdk_argv)[i] = (char*)malloc(arg_size[i]);

if ((*dpdk_argv)[i] == NULL) {
while (i != 0) {
free((*dpdk_argv)[i]);
i--;
}
printf("Unable to allocate space for **dpdk_argv\n");
free((*dpdk_argv)[0]);
free(*dpdk_argv);
free(core_string);
free(arg_size);
free(mem_channels_string);
return -1;
}
}
Expand Down
3 changes: 3 additions & 0 deletions onvm/onvm_nflib/onvm_flow_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ onvm_ft_create(int cnt, int entry_size) {
hash = rte_hash_find_existing(name);
}

rte_free(name);
if (!hash) {
return NULL;
}
Expand Down Expand Up @@ -238,4 +239,6 @@ void
onvm_ft_free(struct onvm_ft *table) {
rte_hash_reset(table->hash);
rte_hash_free(table->hash);
rte_free(table->data);
rte_free(table);
}
2 changes: 1 addition & 1 deletion onvm/onvm_nflib/onvm_flow_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ onvm_ft_ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len, uint32_t
const uint32_t *p;

k = (union ipv4_5tuple_host*) malloc(sizeof(union ipv4_5tuple_host));
memcpy(k, data, sizeof(union ipv4_5tuple_host));
rte_memcpy(k, data, sizeof(union ipv4_5tuple_host));

t = k->proto;
p = (const uint32_t *)&k->port_src;
Expand Down
Loading