Message ID | IA0PPF73BED5E32493C81A3FE43E67F5464CD96A@IA0PPF73BED5E32.namprd12.prod.outlook.com |
---|---|
State | Changes Requested |
Delegated to: | Ilya Maximets |
Headers | show |
Series | [ovs-dev,v3] ovsdb: Use static json objects to reduce memory allocator usage. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/cirrus-robot | success | cirrus build: passed |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: > The idea of this change is to reduce memory allocations/deallocations > for constant json objects like "uuid", "named_uuid", "map", etc. > > Signed-off-by: Dmitry Porokh <dporokh@nvidia.com> > --- > Notes: > v2/v3: > - style & max line length fixes Please ensure that all patches are tested locally before submission. This includes running checkpatch as well as the test suite. Both GitHub Actions and Cirrus CI are available for free on personal forks, so please take advantage of these tools before sending changes upstream, if you don't want to run tests manually. And wait for human feedback for at least 24 hours or, more realistically, a few days before sending new revisions. Shooting out patches without testing them only wastes resources of the shared CI infrastructure and everyone's time. Best regards, Ilya Maximets.
Hi Ilya, I apologize for inconvenience. I would love to run all possible tests before sending patches (and I did as contribution guide suggested. https://github.com/openvswitch/ovs/blob/main/Documentation/internals/contributing/submitting-patches.rst#id1, but apparently recommended make distcheck doesn't include coding style checks). Thanks, Dmitry
Dmitry Porokh via dev <ovs-dev@openvswitch.org> writes: > Hi Ilya, Hi Dmitry, Please reply inline to the list rather than top posting. Top posts are generally harder to follow for discussion. > I apologize for inconvenience. I would love to run all possible tests > before sending patches (and I did as contribution guide suggested. > https://github.com/openvswitch/ovs/blob/main/Documentation/internals/contributing/submitting-patches.rst#id1, > but apparently recommended make distcheck doesn't include coding style checks). Note that the document also has the following:: If your code is non-datapath code, you may use the utilities/checkpatch.py utility as a quick check for certain commonly occurring mistakes (improper leading/trailing whitespace, missing signoffs, some improper formatted patch files). And even:: If you are using GitHub, then you may utilize the GitHub Actions CI build systems. They will run some of the above tests automatically when you push changes to your repository. However, maybe it seems like that document could be refactored a bit, or even have a checklist type section to follow? Since you are going bootstrapping through the process of contributing, a good follow up might be to take what you learn here and update it to help the next person. WDYT? > Thanks, > Dmitry > > ________________________________________ > From: Ilya Maximets <i.maximets@ovn.org> > Sent: Tuesday, May 13, 2025 11:10 AM > To: Dmitry Porokh <dporokh@nvidia.com>; dev@openvswitch.org > <dev@openvswitch.org> > Cc: i.maximets@ovn.org <i.maximets@ovn.org>; Aaron Conole <aconole@redhat.com> > Subject: Re: [ovs-dev] [PATCH v3] ovsdb: Use static json objects to > reduce memory allocator usage. > > External email: Use caution opening links or attachments > > > On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: >> The idea of this change is to reduce memory allocations/deallocations >> for constant json objects like "uuid", "named_uuid", "map", etc. >> >> Signed-off-by: Dmitry Porokh <dporokh@nvidia.com> >> --- >> Notes: >> v2/v3: >> - style & max line length fixes > > Please ensure that all patches are tested locally before submission. This > includes running checkpatch as well as the test suite. Both GitHub Actions > and Cirrus CI are available for free on personal forks, so please take > advantage of these tools before sending changes upstream, if you don't want > to run tests manually. > > And wait for human feedback for at least 24 hours or, more realistically, > a few days before sending new revisions. > > Shooting out patches without testing them only wastes resources of the shared > CI infrastructure and everyone's time. > > Best regards, Ilya Maximets. > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: > The idea of this change is to reduce memory allocations/deallocations > for constant json objects like "uuid", "named_uuid", "map", etc. Hi, Dmitry. Thanks for the patch and sorry for delay. Do you have any performance numbers for this change to show the improvement? I did actually try a very similar approach last year and didn't see any real performance improvement, unfortunately, in neither real-world OVN databases nor synthetic ones. Tried with databases from ovn-kubernetes setups and with ovn-heater. One thing that may have skewed my testing is that I tried this optimization on top of inlining the short strings and arrays into the json struct: https://github.com/igsilya/ovs/commit/5f545e6a0b6cdfed40798efca054e67dafdd66b2 (I need to clean this up and post someday.) but I'm not sure. The impact of these pre-defined short strings seems negligible in comparison with the rest of memory allocations we do for json objects. Best regards, Ilya Maximets.
Ilya Maximets <i.maximets@ovn.org> writes: > External email: Use caution opening links or attachments > > > On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: >> The idea of this change is to reduce memory allocations/deallocations >> for constant json objects like "uuid", "named_uuid", "map", etc. > > Hi, Dmitry. Thanks for the patch and sorry for delay. > > Do you have any performance numbers for this change to show the improvement? I don't believe that performance improvement from this change can be really measured on full system. But probably I can do some microbenchmark that shows that statics are better and adding additional condition in if in deallocation can be ignored. Also, protect this change a bit I would ask: "Would you try to remove it if it already had been there?". In addition, IMO constants in one place is better than constants scattered across the code. But if your opinion is different I can just give up. Not fight worth having. > I did actually try a very similar approach last year and didn't see any real > performance improvement, unfortunately, in neither real-world OVN databases > nor synthetic ones. Tried with databases from ovn-kubernetes setups and with > ovn-heater. > > One thing that may have skewed my testing is that I tried this optimization > on top of inlining the short strings and arrays into the json struct: > https://github.com/igsilya/ovs/commit/5f545e6a0b6cdfed40798efca054e67dafdd66b2 > (I need to clean this up and post someday.) > but I'm not sure. The impact of these pre-defined short strings seems > negligible in comparison with the rest of memory allocations we do for json > objects. > > Best regards, Ilya Maximets. Thanks, Dmitry
On 5/29/25 11:37 PM, Dmitry Porokh wrote: > > Ilya Maximets <i.maximets@ovn.org> writes: > >> External email: Use caution opening links or attachments >> >> >> On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: >>> The idea of this change is to reduce memory allocations/deallocations >>> for constant json objects like "uuid", "named_uuid", "map", etc. >> >> Hi, Dmitry. Thanks for the patch and sorry for delay. >> >> Do you have any performance numbers for this change to show the improvement? > > I don't believe that performance improvement from this change can be > really measured on full system. But probably I can do some > microbenchmark that shows that statics are better and adding additional > condition in if in deallocation can be ignored. OK, I was just curious if you saw a noticeable performance improvement with this change, since I haven't in my tests. It may be worth mentioning in the commit message. > > Also, protect this change a bit I would ask: "Would you try to remove it if > it already had been there?". In addition, IMO constants in one place is > better than constants scattered across the code. Sure, I do think that it's a reasonable change overall and, as I said below, I even tried the very similar approach myself some time ago. So, I think, it's fine to get it accepted. I'll post some technical comments for the patch. Best regards, Ilya Maximets. > > But if your opinion is different I can just give up. Not fight worth having. > >> I did actually try a very similar approach last year and didn't see any real >> performance improvement, unfortunately, in neither real-world OVN databases >> nor synthetic ones. Tried with databases from ovn-kubernetes setups and with >> ovn-heater. >> >> One thing that may have skewed my testing is that I tried this optimization >> on top of inlining the short strings and arrays into the json struct: >> https://github.com/igsilya/ovs/commit/5f545e6a0b6cdfed40798efca054e67dafdd66b2 >> (I need to clean this up and post someday.) >> but I'm not sure. The impact of these pre-defined short strings seems >> negligible in comparison with the rest of memory allocations we do for json >> objects. >> >> Best regards, Ilya Maximets. > > Thanks, > Dmitry >
On 5/13/25 7:23 PM, Dmitry Porokh via dev wrote: > The idea of this change is to reduce memory allocations/deallocations > for constant json objects like "uuid", "named_uuid", "map", etc. > > Signed-off-by: Dmitry Porokh <dporokh@nvidia.com> > --- > Notes: > v2/v3: > - style & max line length fixes > > include/openvswitch/json.h | 17 +++++++++++- > lib/automake.mk | 2 ++ > lib/json.c | 5 ++++ > lib/json.h | 2 +- > lib/ovsdb-cs.c | 3 +- > lib/ovsdb-data.c | 16 +++++++---- > lib/ovsdb-idl.c | 57 ++++++++++++++++++++------------------ > lib/ovsdb-json.c | 42 ++++++++++++++++++++++++++++ > lib/ovsdb-json.h | 50 +++++++++++++++++++++++++++++++++ > 9 files changed, 158 insertions(+), 36 deletions(-) > create mode 100644 lib/ovsdb-json.c > create mode 100644 lib/ovsdb-json.h > > diff --git a/include/openvswitch/json.h b/include/openvswitch/json.h > index 097bd057d..7a87b809d 100644 > --- a/include/openvswitch/json.h > +++ b/include/openvswitch/json.h > @@ -67,6 +67,7 @@ struct json_array { > struct json { > enum json_type type; > size_t count; > + bool is_static; /* Json with static data */ We should not need this. If the static object initialized with count == 2, then it should never be freed. And if it's freed, then we have a bug somewhere and we need to fix that code instead. It also taking up the current hole in the structure that can be used for something else in the future, e.g. indicator of internal layout. > union { > struct shash *object; /* Contains "struct json *"s. */ > struct json_array array; > @@ -76,6 +77,20 @@ struct json { > }; > }; > > +#define JSON_STATIC_STRING_INITIALIZER(value) { \ > + .type = JSON_STRING, \ > + .count = 1, \ > + .is_static = true, \ > + .string = value \ nit: Add a comma at the end. And 4 spaces is enough for indentation. > +} > + > +#define JSON_STATIC_INT_INITIALIZER(value) { \ > + .type = JSON_INTEGER, \ > + .count = 1, \ > + .is_static = true, \ > + .integer = value \ Same here. > +} > + > struct json *json_null_create(void); > struct json *json_boolean_create(bool); > struct json *json_string_create(const char *); > @@ -168,7 +183,7 @@ void json_destroy__(struct json *json, bool); > static inline void > json_destroy(struct json *json) > { > - if (json && !--json->count) { > + if (json && !json->is_static && !--json->count) { > json_destroy__(json, false); > } > } > diff --git a/lib/automake.mk b/lib/automake.mk > index 78d6e6516..f73bc2db1 100644 > --- a/lib/automake.mk > +++ b/lib/automake.mk > @@ -289,6 +289,8 @@ lib_libopenvswitch_la_SOURCES = \ > lib/ovsdb-idl-provider.h \ > lib/ovsdb-idl.c \ > lib/ovsdb-idl.h \ > + lib/ovsdb-json.c \ > + lib/ovsdb-json.h \ > lib/ovsdb-map-op.c \ > lib/ovsdb-map-op.h \ > lib/ovsdb-set-op.c \ > diff --git a/lib/json.c b/lib/json.c > index 2649e8e12..1d380d0ed 100644 > --- a/lib/json.c > +++ b/lib/json.c > @@ -409,6 +409,10 @@ static void json_destroy_array(struct json_array *array, bool yield); > void > json_destroy__(struct json *json, bool yield) > { > + if (json->is_static) { > + return; > + } > + > switch (json->type) { > case JSON_OBJECT: > json_destroy_object(json->object, yield); > @@ -1547,6 +1551,7 @@ json_create(enum json_type type) > struct json *json = xmalloc(sizeof *json); > json->type = type; > json->count = 1; > + json->is_static = false; > return json; > } > > diff --git a/lib/json.h b/lib/json.h > index 4ad440b39..08fe12c2d 100644 > --- a/lib/json.h > +++ b/lib/json.h > @@ -22,7 +22,7 @@ > static inline void > json_destroy_with_yield(struct json *json) > { > - if (json && !--json->count) { > + if (json && !json->is_static && !--json->count) { > json_destroy__(json, true); > } > } > diff --git a/lib/ovsdb-cs.c b/lib/ovsdb-cs.c > index 87c6211bf..9a9bf05f5 100644 > --- a/lib/ovsdb-cs.c > +++ b/lib/ovsdb-cs.c > @@ -30,6 +30,7 @@ > #include "openvswitch/vlog.h" > #include "ovsdb-data.h" > #include "ovsdb-error.h" > +#include "ovsdb-json.h" > #include "ovsdb-parser.h" > #include "ovsdb-session.h" > #include "ovsdb-types.h" > @@ -298,7 +299,7 @@ ovsdb_cs_db_init(struct ovsdb_cs_db *db, const char *db_name, > .db_name = db_name, > .tables = HMAP_INITIALIZER(&db->tables), > .max_version = max_version, > - .monitor_id = json_array_create_2(json_string_create("monid"), > + .monitor_id = json_array_create_2(&OVSDB_JSON_STR_MONID, > json_string_create(db_name)), > .events = OVS_LIST_INITIALIZER(&db->events), > .ops = ops, > diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c > index e4149401f..5679b858d 100644 > --- a/lib/ovsdb-data.c > +++ b/lib/ovsdb-data.c > @@ -26,6 +26,7 @@ > #include "hash.h" > #include "ovs-thread.h" > #include "ovsdb-error.h" > +#include "ovsdb-json.h" > #include "ovsdb-parser.h" > #include "openvswitch/json.h" > #include "openvswitch/shash.h" > @@ -35,9 +36,9 @@ > #include "util.h" > > static struct json * > -wrap_json(const char *name, struct json *wrapped) > +wrap_json(struct json *name, struct json *wrapped) > { > - return json_array_create_2(json_string_create(name), wrapped); > + return json_array_create_2(name, wrapped); > } > > /* Initializes 'atom' with the default value of the given 'type'. > @@ -483,7 +484,8 @@ ovsdb_atom_to_json__(const union ovsdb_atom *atom, enum ovsdb_atomic_type type, > : json_deep_clone(atom->s); > > case OVSDB_TYPE_UUID: > - return wrap_json("uuid", json_string_create_uuid(&atom->uuid)); > + return wrap_json(&OVSDB_JSON_STR_UUID, > + json_string_create_uuid(&atom->uuid)); > > case OVSDB_N_TYPES: > default: > @@ -1439,7 +1441,7 @@ ovsdb_base_to_json(const union ovsdb_atom *atom, > : ovsdb_atom_to_json_deep(atom, base->type); > } else { > return json_array_create_2( > - json_string_create("named-uuid"), > + &OVSDB_JSON_STR_NAMED_UUID, > json_string_create_nocopy(ovsdb_data_row_name(&atom->uuid))); > } > } > @@ -1463,7 +1465,8 @@ ovsdb_datum_to_json__(const struct ovsdb_datum *datum, > use_row_names, allow_shallow_copies)); > } > > - return wrap_json("map", json_array_create(elems, datum->n)); > + return wrap_json(&OVSDB_JSON_STR_MAP, > + json_array_create(elems, datum->n)); > } else if (datum->n == 1) { > return ovsdb_base_to_json(&datum->keys[0], &type->key, > use_row_names, allow_shallow_copies); > @@ -1477,7 +1480,8 @@ ovsdb_datum_to_json__(const struct ovsdb_datum *datum, > use_row_names, allow_shallow_copies); > } > > - return wrap_json("set", json_array_create(elems, datum->n)); > + return wrap_json(&OVSDB_JSON_STR_SET, > + json_array_create(elems, datum->n)); > } > } > > diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c > index 226a4b475..cd51336c3 100644 > --- a/lib/ovsdb-idl.c > +++ b/lib/ovsdb-idl.c > @@ -36,6 +36,7 @@ > #include "ovsdb-data.h" > #include "ovsdb-error.h" > #include "ovsdb-idl-provider.h" > +#include "ovsdb-json.h" > #include "ovsdb-parser.h" > #include "ovsdb-server-idl.h" > #include "ovsdb-session.h" > @@ -2834,10 +2835,10 @@ where_uuid_equals(const struct uuid *uuid) > return > json_array_create_1( > json_array_create_3( > - json_string_create("_uuid"), > - json_string_create("=="), > + &OVSDB_JSON_STR__UUID, > + &OVSDB_JSON_STR_EQ, > json_array_create_2( > - json_string_create("uuid"), > + &OVSDB_JSON_STR_UUID, > json_string_create_uuid(uuid)))); > } > > @@ -2865,7 +2866,8 @@ substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn) > if (json->array.n == 2 > && json->array.elems[0]->type == JSON_STRING > && json->array.elems[1]->type == JSON_STRING > - && !strcmp(json->array.elems[0]->string, "uuid") > + && !strcmp(json->array.elems[0]->string, > + OVSDB_JSON_STR_UUID.string) > && uuid_from_string(&uuid, json->array.elems[1]->string)) { > const struct ovsdb_idl_row *row; > > @@ -2876,7 +2878,7 @@ substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn) > } else { > json_destroy(json); > return json_array_create_2( > - json_string_create("named-uuid"), > + &OVSDB_JSON_STR_NAMED_UUID, > json_string_create_nocopy(ovsdb_data_row_name(&uuid))); > } > } > @@ -3044,8 +3046,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, > > if (any_del) { > col_name = json_string_create(column->name); > - mutator = json_string_create("delete"); > - map = json_array_create_2(json_string_create("set"), del_set); > + mutator = &OVSDB_JSON_STR_DELETE; > + map = json_array_create_2(&OVSDB_JSON_STR_SET, del_set); > mutation = json_array_create_3(col_name, mutator, map); > json_array_add(mutations, mutation); > any_mutations = true; > @@ -3054,8 +3056,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, > } > if (any_ins) { > col_name = json_string_create(column->name); > - mutator = json_string_create("insert"); > - map = json_array_create_2(json_string_create("map"), ins_map); > + mutator = &OVSDB_JSON_STR_INSERT; > + map = json_array_create_2(&OVSDB_JSON_STR_MAP, ins_map); > mutation = json_array_create_3(col_name, mutator, map); > json_array_add(mutations, mutation); > any_mutations = true; > @@ -3118,8 +3120,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, > } > if (any_del) { > col_name = json_string_create(column->name); > - mutator = json_string_create("delete"); > - set = json_array_create_2(json_string_create("set"), del_set); > + mutator = &OVSDB_JSON_STR_DELETE; > + set = json_array_create_2(&OVSDB_JSON_STR_SET, del_set); > mutation = json_array_create_3(col_name, mutator, set); > json_array_add(mutations, mutation); > any_mutations = true; > @@ -3128,8 +3130,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, > } > if (any_ins) { > col_name = json_string_create(column->name); > - mutator = json_string_create("insert"); > - set = json_array_create_2(json_string_create("set"), ins_set); > + mutator = &OVSDB_JSON_STR_INSERT; > + set = json_array_create_2(&OVSDB_JSON_STR_SET, ins_set); > mutation = json_array_create_3(col_name, mutator, set); > json_array_add(mutations, mutation); > any_mutations = true; > @@ -3219,11 +3221,11 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > > op = json_object_create(); > json_array_add(operations, op); > - json_object_put_string(op, "op", "wait"); > + json_object_put(op, "op", &OVSDB_JSON_STR_WAIT); > json_object_put_string(op, "table", class->name); > json_object_put(op, "timeout", json_integer_create(0)); > json_object_put(op, "where", where_uuid_equals(&row->uuid)); > - json_object_put_string(op, "until", "=="); > + json_object_put(op, "until", &OVSDB_JSON_STR_EQ); > columns = json_array_create_empty(); > json_object_put(op, "columns", columns); > row_json = json_object_create(); > @@ -3264,11 +3266,11 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > if (initial_rows == 0 && final_rows == 1) { > struct json *op = json_object_create(); > json_array_add(operations, op); > - json_object_put_string(op, "op", "wait"); > + json_object_put(op, "op", &OVSDB_JSON_STR_WAIT); > json_object_put_string(op, "table", table->class_->name); > json_object_put(op, "where", json_array_create_empty()); > json_object_put(op, "timeout", json_integer_create(0)); > - json_object_put_string(op, "until", "=="); > + json_object_put(op, "until", &OVSDB_JSON_STR_EQ); > json_object_put(op, "rows", json_array_create_empty()); > } > } > @@ -3280,7 +3282,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > if (!row->new_datum) { > if (class->is_root) { > struct json *op = json_object_create(); > - json_object_put_string(op, "op", "delete"); > + json_object_put(op, "op", &OVSDB_JSON_STR_DELETE); > json_object_put_string(op, "table", class->name); > json_object_put(op, "where", where_uuid_equals(&row->uuid)); > json_array_add(operations, op); > @@ -3293,8 +3295,9 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > size_t idx; > > struct json *op = json_object_create(); > - json_object_put_string(op, "op", > - row->old_datum ? "update" : "insert"); > + json_object_put(op, "op", > + row->old_datum ? &OVSDB_JSON_STR_UPDATE > + : &OVSDB_JSON_STR_INSERT); > json_object_put_string(op, "table", class->name); > if (row->old_datum) { > json_object_put(op, "where", where_uuid_equals(&row->uuid)); > @@ -3368,7 +3371,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > bool any_mutations; > > op = json_object_create(); > - json_object_put_string(op, "op", "mutate"); > + json_object_put(op, "op", &OVSDB_JSON_STR_MUTATE); > json_object_put_string(op, "table", class->name); > json_object_put(op, "where", where_uuid_equals(&row->uuid)); > mutations = json_array_create_empty(); > @@ -3391,7 +3394,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > txn->inc_index = operations->array.n - 1; > > struct json *op = json_object_create(); > - json_object_put_string(op, "op", "mutate"); > + json_object_put(op, "op", &OVSDB_JSON_STR_MUTATE); > json_object_put_string(op, "table", txn->inc_table); > json_object_put(op, "where", > substitute_uuids(where_uuid_equals(&txn->inc_row), > @@ -3400,12 +3403,12 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > json_array_create_1( > json_array_create_3( > json_string_create(txn->inc_column), > - json_string_create("+="), > - json_integer_create(1)))); > + &OVSDB_JSON_STR_ADD_EQ, > + &OVSDB_JSON_INTEGER_ONE))); > json_array_add(operations, op); > > op = json_object_create(); > - json_object_put_string(op, "op", "select"); > + json_object_put(op, "op", &OVSDB_JSON_STR_SELECT); > json_object_put_string(op, "table", txn->inc_table); > json_object_put(op, "where", > substitute_uuids(where_uuid_equals(&txn->inc_row), > @@ -3418,14 +3421,14 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) > > if (txn->comment.length) { > struct json *op = json_object_create(); > - json_object_put_string(op, "op", "comment"); > + json_object_put(op, "op", &OVSDB_JSON_STR_COMMENT); > json_object_put_string(op, "comment", ds_cstr(&txn->comment)); > json_array_add(operations, op); > } > > if (txn->dry_run) { > struct json *op = json_object_create(); > - json_object_put_string(op, "op", "abort"); > + json_object_put(op, "op", &OVSDB_JSON_STR_ABORT); > json_array_add(operations, op); > } > > diff --git a/lib/ovsdb-json.c b/lib/ovsdb-json.c > new file mode 100644 > index 000000000..382970016 > --- /dev/null > +++ b/lib/ovsdb-json.c > @@ -0,0 +1,42 @@ > +/* > + * Copyright (c) 2025 NVIDIA Corporation. > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at: > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +#include <config.h> > + > +#include "openvswitch/json.h" > +#include "ovsdb-json.h" > + > +struct json OVSDB_JSON_INTEGER_ONE = JSON_STATIC_INT_INITIALIZER(1); > +struct json OVSDB_JSON_STR_ABORT = JSON_STATIC_STRING_INITIALIZER("abort"); > +struct json OVSDB_JSON_STR_ADD_EQ = JSON_STATIC_STRING_INITIALIZER("+="); > +struct json OVSDB_JSON_STR_COMMENT = JSON_STATIC_STRING_INITIALIZER("comment"); > +struct json OVSDB_JSON_STR_DELETE = JSON_STATIC_STRING_INITIALIZER("delete"); > +struct json OVSDB_JSON_STR_EQ = JSON_STATIC_STRING_INITIALIZER("==" ); > +struct json OVSDB_JSON_STR_INSERT = JSON_STATIC_STRING_INITIALIZER("insert"); > +struct json OVSDB_JSON_STR_MAP = JSON_STATIC_STRING_INITIALIZER("map"); > +struct json OVSDB_JSON_STR_MONID = JSON_STATIC_STRING_INITIALIZER("monid"); > +struct json OVSDB_JSON_STR_MUTATE = JSON_STATIC_STRING_INITIALIZER("mutate"); > +struct json OVSDB_JSON_STR_SELECT = JSON_STATIC_STRING_INITIALIZER("select"); > +struct json OVSDB_JSON_STR_SET = JSON_STATIC_STRING_INITIALIZER("set"); > +struct json OVSDB_JSON_STR_UPDATE = JSON_STATIC_STRING_INITIALIZER("update"); > +struct json OVSDB_JSON_STR_UUID = JSON_STATIC_STRING_INITIALIZER("uuid"); > +struct json OVSDB_JSON_STR_WAIT = JSON_STATIC_STRING_INITIALIZER("wait"); > +struct json OVSDB_JSON_STR__UUID = JSON_STATIC_STRING_INITIALIZER("_uuid"); > +struct json OVSDB_JSON_STR_NAMED_UUID = > + JSON_STATIC_STRING_INITIALIZER("named-uuid"); Do we need a separate header and a c file for these? Maybe we can put them in ovsdb-data? We have json conversion functions there, so it wouldn't be a big stretch. Also, I think, it's important to highlight in the names that these are static. To not make them too long, maybe we can ditch the OVSDB part and replace it with STATIC? e.g. JSON_STATIC_STR_*. And it might be better to group the strings by the purpose and have an empty line between groups. You sorted them by name, but also not fully as the named uuid ended up last, so it's a bit of a mess. It's better if we group the liternal operations, math operations, monitor stuff, data structures separately. Maybe a seraprate group for things related to UUIDs. > + > + > + Shouldn't need these. > diff --git a/lib/ovsdb-json.h b/lib/ovsdb-json.h > new file mode 100644 > index 000000000..a5f9f8fce > --- /dev/null > +++ b/lib/ovsdb-json.h > @@ -0,0 +1,50 @@ > +/* > + * Copyright (c) 2025 NVIDIA Corporation. > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at: > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +#ifndef OVSDB_JSON_H > +#define OVSDB_JSON_H > + > +#include <config.h> > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +struct json; > + > +extern struct json OVSDB_JSON_INTEGER_ONE; /* 1 */ > +extern struct json OVSDB_JSON_STR_ABORT; /* "abort" */ > +extern struct json OVSDB_JSON_STR_ADD_EQ; /* "+=" */ > +extern struct json OVSDB_JSON_STR_COMMENT; /* "comment" */ > +extern struct json OVSDB_JSON_STR_DELETE; /* "delete" */ > +extern struct json OVSDB_JSON_STR_EQ; /* "==" */ > +extern struct json OVSDB_JSON_STR_INSERT; /* "insert" */ > +extern struct json OVSDB_JSON_STR_MAP; /* "map" */ > +extern struct json OVSDB_JSON_STR_MONID; /* "monid" */ > +extern struct json OVSDB_JSON_STR_MUTATE; /* "mutate" */ > +extern struct json OVSDB_JSON_STR_NAMED_UUID; /* "named-uuid" */ > +extern struct json OVSDB_JSON_STR_SELECT; /* "select" */ > +extern struct json OVSDB_JSON_STR_SET; /* "set" */ > +extern struct json OVSDB_JSON_STR_UPDATE; /* "update" */ > +extern struct json OVSDB_JSON_STR_UUID; /* "uuid" */ > +extern struct json OVSDB_JSON_STR_WAIT; /* "wait" */ > +extern struct json OVSDB_JSON_STR__UUID; /* "_uuid" */; > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif Best regards, Ilya Maximets.
diff --git a/include/openvswitch/json.h b/include/openvswitch/json.h index 097bd057d..7a87b809d 100644 --- a/include/openvswitch/json.h +++ b/include/openvswitch/json.h @@ -67,6 +67,7 @@ struct json_array { struct json { enum json_type type; size_t count; + bool is_static; /* Json with static data */ union { struct shash *object; /* Contains "struct json *"s. */ struct json_array array; @@ -76,6 +77,20 @@ struct json { }; }; +#define JSON_STATIC_STRING_INITIALIZER(value) { \ + .type = JSON_STRING, \ + .count = 1, \ + .is_static = true, \ + .string = value \ +} + +#define JSON_STATIC_INT_INITIALIZER(value) { \ + .type = JSON_INTEGER, \ + .count = 1, \ + .is_static = true, \ + .integer = value \ +} + struct json *json_null_create(void); struct json *json_boolean_create(bool); struct json *json_string_create(const char *); @@ -168,7 +183,7 @@ void json_destroy__(struct json *json, bool); static inline void json_destroy(struct json *json) { - if (json && !--json->count) { + if (json && !json->is_static && !--json->count) { json_destroy__(json, false); } } diff --git a/lib/automake.mk b/lib/automake.mk index 78d6e6516..f73bc2db1 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -289,6 +289,8 @@ lib_libopenvswitch_la_SOURCES = \ lib/ovsdb-idl-provider.h \ lib/ovsdb-idl.c \ lib/ovsdb-idl.h \ + lib/ovsdb-json.c \ + lib/ovsdb-json.h \ lib/ovsdb-map-op.c \ lib/ovsdb-map-op.h \ lib/ovsdb-set-op.c \ diff --git a/lib/json.c b/lib/json.c index 2649e8e12..1d380d0ed 100644 --- a/lib/json.c +++ b/lib/json.c @@ -409,6 +409,10 @@ static void json_destroy_array(struct json_array *array, bool yield); void json_destroy__(struct json *json, bool yield) { + if (json->is_static) { + return; + } + switch (json->type) { case JSON_OBJECT: json_destroy_object(json->object, yield); @@ -1547,6 +1551,7 @@ json_create(enum json_type type) struct json *json = xmalloc(sizeof *json); json->type = type; json->count = 1; + json->is_static = false; return json; } diff --git a/lib/json.h b/lib/json.h index 4ad440b39..08fe12c2d 100644 --- a/lib/json.h +++ b/lib/json.h @@ -22,7 +22,7 @@ static inline void json_destroy_with_yield(struct json *json) { - if (json && !--json->count) { + if (json && !json->is_static && !--json->count) { json_destroy__(json, true); } } diff --git a/lib/ovsdb-cs.c b/lib/ovsdb-cs.c index 87c6211bf..9a9bf05f5 100644 --- a/lib/ovsdb-cs.c +++ b/lib/ovsdb-cs.c @@ -30,6 +30,7 @@ #include "openvswitch/vlog.h" #include "ovsdb-data.h" #include "ovsdb-error.h" +#include "ovsdb-json.h" #include "ovsdb-parser.h" #include "ovsdb-session.h" #include "ovsdb-types.h" @@ -298,7 +299,7 @@ ovsdb_cs_db_init(struct ovsdb_cs_db *db, const char *db_name, .db_name = db_name, .tables = HMAP_INITIALIZER(&db->tables), .max_version = max_version, - .monitor_id = json_array_create_2(json_string_create("monid"), + .monitor_id = json_array_create_2(&OVSDB_JSON_STR_MONID, json_string_create(db_name)), .events = OVS_LIST_INITIALIZER(&db->events), .ops = ops, diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index e4149401f..5679b858d 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -26,6 +26,7 @@ #include "hash.h" #include "ovs-thread.h" #include "ovsdb-error.h" +#include "ovsdb-json.h" #include "ovsdb-parser.h" #include "openvswitch/json.h" #include "openvswitch/shash.h" @@ -35,9 +36,9 @@ #include "util.h" static struct json * -wrap_json(const char *name, struct json *wrapped) +wrap_json(struct json *name, struct json *wrapped) { - return json_array_create_2(json_string_create(name), wrapped); + return json_array_create_2(name, wrapped); } /* Initializes 'atom' with the default value of the given 'type'. @@ -483,7 +484,8 @@ ovsdb_atom_to_json__(const union ovsdb_atom *atom, enum ovsdb_atomic_type type, : json_deep_clone(atom->s); case OVSDB_TYPE_UUID: - return wrap_json("uuid", json_string_create_uuid(&atom->uuid)); + return wrap_json(&OVSDB_JSON_STR_UUID, + json_string_create_uuid(&atom->uuid)); case OVSDB_N_TYPES: default: @@ -1439,7 +1441,7 @@ ovsdb_base_to_json(const union ovsdb_atom *atom, : ovsdb_atom_to_json_deep(atom, base->type); } else { return json_array_create_2( - json_string_create("named-uuid"), + &OVSDB_JSON_STR_NAMED_UUID, json_string_create_nocopy(ovsdb_data_row_name(&atom->uuid))); } } @@ -1463,7 +1465,8 @@ ovsdb_datum_to_json__(const struct ovsdb_datum *datum, use_row_names, allow_shallow_copies)); } - return wrap_json("map", json_array_create(elems, datum->n)); + return wrap_json(&OVSDB_JSON_STR_MAP, + json_array_create(elems, datum->n)); } else if (datum->n == 1) { return ovsdb_base_to_json(&datum->keys[0], &type->key, use_row_names, allow_shallow_copies); @@ -1477,7 +1480,8 @@ ovsdb_datum_to_json__(const struct ovsdb_datum *datum, use_row_names, allow_shallow_copies); } - return wrap_json("set", json_array_create(elems, datum->n)); + return wrap_json(&OVSDB_JSON_STR_SET, + json_array_create(elems, datum->n)); } } diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 226a4b475..cd51336c3 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -36,6 +36,7 @@ #include "ovsdb-data.h" #include "ovsdb-error.h" #include "ovsdb-idl-provider.h" +#include "ovsdb-json.h" #include "ovsdb-parser.h" #include "ovsdb-server-idl.h" #include "ovsdb-session.h" @@ -2834,10 +2835,10 @@ where_uuid_equals(const struct uuid *uuid) return json_array_create_1( json_array_create_3( - json_string_create("_uuid"), - json_string_create("=="), + &OVSDB_JSON_STR__UUID, + &OVSDB_JSON_STR_EQ, json_array_create_2( - json_string_create("uuid"), + &OVSDB_JSON_STR_UUID, json_string_create_uuid(uuid)))); } @@ -2865,7 +2866,8 @@ substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn) if (json->array.n == 2 && json->array.elems[0]->type == JSON_STRING && json->array.elems[1]->type == JSON_STRING - && !strcmp(json->array.elems[0]->string, "uuid") + && !strcmp(json->array.elems[0]->string, + OVSDB_JSON_STR_UUID.string) && uuid_from_string(&uuid, json->array.elems[1]->string)) { const struct ovsdb_idl_row *row; @@ -2876,7 +2878,7 @@ substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn) } else { json_destroy(json); return json_array_create_2( - json_string_create("named-uuid"), + &OVSDB_JSON_STR_NAMED_UUID, json_string_create_nocopy(ovsdb_data_row_name(&uuid))); } } @@ -3044,8 +3046,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, if (any_del) { col_name = json_string_create(column->name); - mutator = json_string_create("delete"); - map = json_array_create_2(json_string_create("set"), del_set); + mutator = &OVSDB_JSON_STR_DELETE; + map = json_array_create_2(&OVSDB_JSON_STR_SET, del_set); mutation = json_array_create_3(col_name, mutator, map); json_array_add(mutations, mutation); any_mutations = true; @@ -3054,8 +3056,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, } if (any_ins) { col_name = json_string_create(column->name); - mutator = json_string_create("insert"); - map = json_array_create_2(json_string_create("map"), ins_map); + mutator = &OVSDB_JSON_STR_INSERT; + map = json_array_create_2(&OVSDB_JSON_STR_MAP, ins_map); mutation = json_array_create_3(col_name, mutator, map); json_array_add(mutations, mutation); any_mutations = true; @@ -3118,8 +3120,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, } if (any_del) { col_name = json_string_create(column->name); - mutator = json_string_create("delete"); - set = json_array_create_2(json_string_create("set"), del_set); + mutator = &OVSDB_JSON_STR_DELETE; + set = json_array_create_2(&OVSDB_JSON_STR_SET, del_set); mutation = json_array_create_3(col_name, mutator, set); json_array_add(mutations, mutation); any_mutations = true; @@ -3128,8 +3130,8 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row, } if (any_ins) { col_name = json_string_create(column->name); - mutator = json_string_create("insert"); - set = json_array_create_2(json_string_create("set"), ins_set); + mutator = &OVSDB_JSON_STR_INSERT; + set = json_array_create_2(&OVSDB_JSON_STR_SET, ins_set); mutation = json_array_create_3(col_name, mutator, set); json_array_add(mutations, mutation); any_mutations = true; @@ -3219,11 +3221,11 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) op = json_object_create(); json_array_add(operations, op); - json_object_put_string(op, "op", "wait"); + json_object_put(op, "op", &OVSDB_JSON_STR_WAIT); json_object_put_string(op, "table", class->name); json_object_put(op, "timeout", json_integer_create(0)); json_object_put(op, "where", where_uuid_equals(&row->uuid)); - json_object_put_string(op, "until", "=="); + json_object_put(op, "until", &OVSDB_JSON_STR_EQ); columns = json_array_create_empty(); json_object_put(op, "columns", columns); row_json = json_object_create(); @@ -3264,11 +3266,11 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) if (initial_rows == 0 && final_rows == 1) { struct json *op = json_object_create(); json_array_add(operations, op); - json_object_put_string(op, "op", "wait"); + json_object_put(op, "op", &OVSDB_JSON_STR_WAIT); json_object_put_string(op, "table", table->class_->name); json_object_put(op, "where", json_array_create_empty()); json_object_put(op, "timeout", json_integer_create(0)); - json_object_put_string(op, "until", "=="); + json_object_put(op, "until", &OVSDB_JSON_STR_EQ); json_object_put(op, "rows", json_array_create_empty()); } } @@ -3280,7 +3282,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) if (!row->new_datum) { if (class->is_root) { struct json *op = json_object_create(); - json_object_put_string(op, "op", "delete"); + json_object_put(op, "op", &OVSDB_JSON_STR_DELETE); json_object_put_string(op, "table", class->name); json_object_put(op, "where", where_uuid_equals(&row->uuid)); json_array_add(operations, op); @@ -3293,8 +3295,9 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) size_t idx; struct json *op = json_object_create(); - json_object_put_string(op, "op", - row->old_datum ? "update" : "insert"); + json_object_put(op, "op", + row->old_datum ? &OVSDB_JSON_STR_UPDATE + : &OVSDB_JSON_STR_INSERT); json_object_put_string(op, "table", class->name); if (row->old_datum) { json_object_put(op, "where", where_uuid_equals(&row->uuid)); @@ -3368,7 +3371,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) bool any_mutations; op = json_object_create(); - json_object_put_string(op, "op", "mutate"); + json_object_put(op, "op", &OVSDB_JSON_STR_MUTATE); json_object_put_string(op, "table", class->name); json_object_put(op, "where", where_uuid_equals(&row->uuid)); mutations = json_array_create_empty(); @@ -3391,7 +3394,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) txn->inc_index = operations->array.n - 1; struct json *op = json_object_create(); - json_object_put_string(op, "op", "mutate"); + json_object_put(op, "op", &OVSDB_JSON_STR_MUTATE); json_object_put_string(op, "table", txn->inc_table); json_object_put(op, "where", substitute_uuids(where_uuid_equals(&txn->inc_row), @@ -3400,12 +3403,12 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) json_array_create_1( json_array_create_3( json_string_create(txn->inc_column), - json_string_create("+="), - json_integer_create(1)))); + &OVSDB_JSON_STR_ADD_EQ, + &OVSDB_JSON_INTEGER_ONE))); json_array_add(operations, op); op = json_object_create(); - json_object_put_string(op, "op", "select"); + json_object_put(op, "op", &OVSDB_JSON_STR_SELECT); json_object_put_string(op, "table", txn->inc_table); json_object_put(op, "where", substitute_uuids(where_uuid_equals(&txn->inc_row), @@ -3418,14 +3421,14 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) if (txn->comment.length) { struct json *op = json_object_create(); - json_object_put_string(op, "op", "comment"); + json_object_put(op, "op", &OVSDB_JSON_STR_COMMENT); json_object_put_string(op, "comment", ds_cstr(&txn->comment)); json_array_add(operations, op); } if (txn->dry_run) { struct json *op = json_object_create(); - json_object_put_string(op, "op", "abort"); + json_object_put(op, "op", &OVSDB_JSON_STR_ABORT); json_array_add(operations, op); } diff --git a/lib/ovsdb-json.c b/lib/ovsdb-json.c new file mode 100644 index 000000000..382970016 --- /dev/null +++ b/lib/ovsdb-json.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 NVIDIA Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> + +#include "openvswitch/json.h" +#include "ovsdb-json.h" + +struct json OVSDB_JSON_INTEGER_ONE = JSON_STATIC_INT_INITIALIZER(1); +struct json OVSDB_JSON_STR_ABORT = JSON_STATIC_STRING_INITIALIZER("abort"); +struct json OVSDB_JSON_STR_ADD_EQ = JSON_STATIC_STRING_INITIALIZER("+="); +struct json OVSDB_JSON_STR_COMMENT = JSON_STATIC_STRING_INITIALIZER("comment"); +struct json OVSDB_JSON_STR_DELETE = JSON_STATIC_STRING_INITIALIZER("delete"); +struct json OVSDB_JSON_STR_EQ = JSON_STATIC_STRING_INITIALIZER("==" ); +struct json OVSDB_JSON_STR_INSERT = JSON_STATIC_STRING_INITIALIZER("insert"); +struct json OVSDB_JSON_STR_MAP = JSON_STATIC_STRING_INITIALIZER("map"); +struct json OVSDB_JSON_STR_MONID = JSON_STATIC_STRING_INITIALIZER("monid"); +struct json OVSDB_JSON_STR_MUTATE = JSON_STATIC_STRING_INITIALIZER("mutate"); +struct json OVSDB_JSON_STR_SELECT = JSON_STATIC_STRING_INITIALIZER("select"); +struct json OVSDB_JSON_STR_SET = JSON_STATIC_STRING_INITIALIZER("set"); +struct json OVSDB_JSON_STR_UPDATE = JSON_STATIC_STRING_INITIALIZER("update"); +struct json OVSDB_JSON_STR_UUID = JSON_STATIC_STRING_INITIALIZER("uuid"); +struct json OVSDB_JSON_STR_WAIT = JSON_STATIC_STRING_INITIALIZER("wait"); +struct json OVSDB_JSON_STR__UUID = JSON_STATIC_STRING_INITIALIZER("_uuid"); +struct json OVSDB_JSON_STR_NAMED_UUID = + JSON_STATIC_STRING_INITIALIZER("named-uuid"); + + + diff --git a/lib/ovsdb-json.h b/lib/ovsdb-json.h new file mode 100644 index 000000000..a5f9f8fce --- /dev/null +++ b/lib/ovsdb-json.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 NVIDIA Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OVSDB_JSON_H +#define OVSDB_JSON_H + +#include <config.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct json; + +extern struct json OVSDB_JSON_INTEGER_ONE; /* 1 */ +extern struct json OVSDB_JSON_STR_ABORT; /* "abort" */ +extern struct json OVSDB_JSON_STR_ADD_EQ; /* "+=" */ +extern struct json OVSDB_JSON_STR_COMMENT; /* "comment" */ +extern struct json OVSDB_JSON_STR_DELETE; /* "delete" */ +extern struct json OVSDB_JSON_STR_EQ; /* "==" */ +extern struct json OVSDB_JSON_STR_INSERT; /* "insert" */ +extern struct json OVSDB_JSON_STR_MAP; /* "map" */ +extern struct json OVSDB_JSON_STR_MONID; /* "monid" */ +extern struct json OVSDB_JSON_STR_MUTATE; /* "mutate" */ +extern struct json OVSDB_JSON_STR_NAMED_UUID; /* "named-uuid" */ +extern struct json OVSDB_JSON_STR_SELECT; /* "select" */ +extern struct json OVSDB_JSON_STR_SET; /* "set" */ +extern struct json OVSDB_JSON_STR_UPDATE; /* "update" */ +extern struct json OVSDB_JSON_STR_UUID; /* "uuid" */ +extern struct json OVSDB_JSON_STR_WAIT; /* "wait" */ +extern struct json OVSDB_JSON_STR__UUID; /* "_uuid" */; + +#ifdef __cplusplus +} +#endif + +#endif
The idea of this change is to reduce memory allocations/deallocations for constant json objects like "uuid", "named_uuid", "map", etc. Signed-off-by: Dmitry Porokh <dporokh@nvidia.com> --- Notes: v2/v3: - style & max line length fixes include/openvswitch/json.h | 17 +++++++++++- lib/automake.mk | 2 ++ lib/json.c | 5 ++++ lib/json.h | 2 +- lib/ovsdb-cs.c | 3 +- lib/ovsdb-data.c | 16 +++++++---- lib/ovsdb-idl.c | 57 ++++++++++++++++++++------------------ lib/ovsdb-json.c | 42 ++++++++++++++++++++++++++++ lib/ovsdb-json.h | 50 +++++++++++++++++++++++++++++++++ 9 files changed, 158 insertions(+), 36 deletions(-) create mode 100644 lib/ovsdb-json.c create mode 100644 lib/ovsdb-json.h