Skip to contentSkip to conversation

perf tools: Enable strict JSON parsing

PATCH In review James Clark 7 participants 18 messages Oct 7, 2021 – Oct 13, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover perf tools: Enable strict JSON parsing

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

James Clark (3):
perf vendor-events: Fix all remaining invalid JSON files perf tools: Make the JSON parser more conformant when in strict mode perf tools: Enable strict JSON parsing

 .../arch/arm64/ampere/emag/bus.json           |  2 +-
 .../arch/arm64/ampere/emag/cache.json         | 20 ++++-----
 .../arch/arm64/ampere/emag/clock.json         |  2 +-
 .../arch/arm64/ampere/emag/exception.json     |  4 +-
 .../arch/arm64/ampere/emag/instruction.json   | 10 ++---
 .../arch/arm64/ampere/emag/memory.json        |  4 +-
 .../arch/arm64/hisilicon/hip08/metrics.json   |  2 +-
 .../pmu-events/arch/nds32/n13/atcpmu.json     |  2 +-
 .../pmu-events/arch/s390/cf_z10/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z10/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z10/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z13/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z13/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z13/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z14/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z14/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z14/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z15/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto6.json  |  2 +-
 .../pmu-events/arch/s390/cf_z15/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z196/basic.json   |  2 +-
 .../pmu-events/arch/s390/cf_z196/crypto.json  |  2 +-
 .../arch/s390/cf_z196/extended.json           |  2 +-
 .../pmu-events/arch/s390/cf_zec12/basic.json  |  2 +-
 .../pmu-events/arch/s390/cf_zec12/crypto.json |  2 +-
 .../arch/s390/cf_zec12/extended.json          |  2 +-
 .../arch/test/test_soc/cpu/uncore.json        |  2 +-
 .../arch/x86/icelakex/icx-metrics.json        |  2 +-
 tools/perf/pmu-events/jsmn.c                  | 43 ++++++++++++++++++-
 30 files changed, 85 insertions(+), 46 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/3 perf vendor-events: Fix all remaining invalid JSON files

Remove trailing commas. A later commit will make the parser more strict and these will not be valid anymore.

---
 .../arch/arm64/ampere/emag/bus.json           |  2 +-
 .../arch/arm64/ampere/emag/cache.json         | 20 +++++++++----------
 .../arch/arm64/ampere/emag/clock.json         |  2 +-
 .../arch/arm64/ampere/emag/exception.json     |  4 ++--
 .../arch/arm64/ampere/emag/instruction.json   | 10 +++++-----
 .../arch/arm64/ampere/emag/memory.json        |  4 ++--
 .../arch/arm64/hisilicon/hip08/metrics.json   |  2 +-
 .../pmu-events/arch/nds32/n13/atcpmu.json     |  2 +-
 .../pmu-events/arch/s390/cf_z10/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z10/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z10/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z13/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z13/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z13/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z14/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z14/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z14/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z15/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto6.json  |  2 +-
 .../pmu-events/arch/s390/cf_z15/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z196/basic.json   |  2 +-
 .../pmu-events/arch/s390/cf_z196/crypto.json  |  2 +-
 .../arch/s390/cf_z196/extended.json           |  2 +-
 .../pmu-events/arch/s390/cf_zec12/basic.json  |  2 +-
 .../pmu-events/arch/s390/cf_zec12/crypto.json |  2 +-
 .../arch/s390/cf_zec12/extended.json          |  2 +-
 .../arch/test/test_soc/cpu/uncore.json        |  2 +-
 .../arch/x86/icelakex/icx-metrics.json        |  2 +-
 29 files changed, 44 insertions(+), 44 deletions(-)
tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json +1 -1
index 9bea1ba1c4d2..cf48d0dfc759 100644
@@ -18,6 +18,6 @@
         "ArchStdEvent": "BUS_ACCESS_PERIPH"
     },
     {
-        "ArchStdEvent": "BUS_ACCESS",
+        "ArchStdEvent": "BUS_ACCESS"
     }
 ]
tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json +10 -10
index 1e25f2ae4ae0..4cc50b7da526 100644
@@ -39,31 +39,31 @@
         "ArchStdEvent": "L2D_CACHE_INVAL"
     },
     {
-        "ArchStdEvent": "L1I_CACHE_REFILL",
+        "ArchStdEvent": "L1I_CACHE_REFILL"
     },
     {
-        "ArchStdEvent": "L1I_TLB_REFILL",
+        "ArchStdEvent": "L1I_TLB_REFILL"
     },
     {
-        "ArchStdEvent": "L1D_CACHE_REFILL",
+        "ArchStdEvent": "L1D_CACHE_REFILL"
     },
     {
-        "ArchStdEvent": "L1D_CACHE",
+        "ArchStdEvent": "L1D_CACHE"
     },
     {
-        "ArchStdEvent": "L1D_TLB_REFILL",
+        "ArchStdEvent": "L1D_TLB_REFILL"
     },
     {
-        "ArchStdEvent": "L1I_CACHE",
+        "ArchStdEvent": "L1I_CACHE"
     },
     {
-        "ArchStdEvent": "L2D_CACHE",
+        "ArchStdEvent": "L2D_CACHE"
     },
     {
-        "ArchStdEvent": "L2D_CACHE_REFILL",
+        "ArchStdEvent": "L2D_CACHE_REFILL"
     },
     {
-        "ArchStdEvent": "L2D_CACHE_WB",
+        "ArchStdEvent": "L2D_CACHE_WB"
     },
     {
         "PublicDescription": "This event counts any load or store operation which accesses the data L1 TLB",
@@ -72,7 +72,7 @@
     },
     {
         "PublicDescription": "This event counts any instruction fetch which accesses the instruction L1 TLB",
-        "ArchStdEvent": "L1I_TLB",
+        "ArchStdEvent": "L1I_TLB"
     },
     {
         "PublicDescription": "Level 2 access to data TLB that caused a page table walk. This event counts on any data access which causes L2D_TLB_REFILL to count",
tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json +1 -1
index 9076ca2daf9e..927a6f629a03 100644
@@ -1,7 +1,7 @@
 [
     {
         "PublicDescription": "The number of core clock cycles",
-        "ArchStdEvent": "CPU_CYCLES",
+        "ArchStdEvent": "CPU_CYCLES"
     },
     {
         "PublicDescription": "FSU clocking gated off cycle",
tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json +2 -2
index 9761433ad329..ada052e19632 100644
@@ -36,9 +36,9 @@
         "ArchStdEvent": "EXC_TRAP_FIQ"
     },
     {
-        "ArchStdEvent": "EXC_TAKEN",
+        "ArchStdEvent": "EXC_TAKEN"
     },
     {
-        "ArchStdEvent": "EXC_RETURN",
+        "ArchStdEvent": "EXC_RETURN"
     }
 ]
tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json +5 -5
index 482aa3f19e58..62f6276e3016 100644
@@ -44,25 +44,25 @@
         "BriefDescription": "Software increment"
     },
     {
-        "ArchStdEvent": "INST_RETIRED",
+        "ArchStdEvent": "INST_RETIRED"
     },
     {
         "ArchStdEvent": "CID_WRITE_RETIRED",
         "BriefDescription": "Write to CONTEXTIDR"
     },
     {
-        "ArchStdEvent": "INST_SPEC",
+        "ArchStdEvent": "INST_SPEC"
     },
     {
-        "ArchStdEvent": "TTBR_WRITE_RETIRED",
+        "ArchStdEvent": "TTBR_WRITE_RETIRED"
     },
     {
         "PublicDescription": "This event counts all branches, taken or not. This excludes exception entries, debug entries and CCFAIL branches",
-        "ArchStdEvent": "BR_RETIRED",
+        "ArchStdEvent": "BR_RETIRED"
     },
     {
         "PublicDescription": "This event counts any branch counted by BR_RETIRED which is not correctly predicted and causes a pipeline flush",
-        "ArchStdEvent": "BR_MIS_PRED_RETIRED",
+        "ArchStdEvent": "BR_MIS_PRED_RETIRED"
     },
     {
         "PublicDescription": "Operation speculatively executed, NOP",
tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json +2 -2
index 2e7555696caf..50157e8c2005 100644
@@ -15,10 +15,10 @@
         "ArchStdEvent": "UNALIGNED_LDST_SPEC"
     },
     {
-        "ArchStdEvent": "MEM_ACCESS",
+        "ArchStdEvent": "MEM_ACCESS"
     },
     {
         "PublicDescription": "This event counts any correctable or uncorrectable memory error (ECC or parity) in the protected core RAMs",
-        "ArchStdEvent": "MEMORY_ERROR",
+        "ArchStdEvent": "MEMORY_ERROR"
     }
 ]
tools/perf/pmu-events/arch/arm64/hisilicon/hip08/metrics.json +1 -1
index dda8e59149d2..6970203cb247 100644
@@ -229,5 +229,5 @@
         "BriefDescription": "Store bound L3 topdown metric",
         "MetricGroup": "TopDownL3",
         "MetricName": "store_bound"
-    },
+    }
 ]
tools/perf/pmu-events/arch/nds32/n13/atcpmu.json +1 -1
index 5347350c360c..3e7ac409d894 100644
@@ -286,5 +286,5 @@
     "EventCode": "0x21e",
     "EventName": "pop25_inst",
     "BriefDescription": "V3 POP25 instructions"
-  },
+  }
 ]
tools/perf/pmu-events/arch/s390/cf_z10/basic.json +1 -1
index 2dd8dafff2ef..783de7f1aeaa 100644
@@ -82,5 +82,5 @@
 		"EventName": "PROBLEM_STATE_L1D_PENALTY_CYCLES",
 		"BriefDescription": "Problem-State L1D Penalty Cycles",
 		"PublicDescription": "Problem-State Level-1 D-Cache Penalty Cycle Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z10/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z10/extended.json +1 -1
index b6b7f29ca831..86bd8ba9391d 100644
@@ -124,5 +124,5 @@
 		"EventName": "L2C_STORES_SENT",
 		"BriefDescription": "L2C Stores Sent",
 		"PublicDescription": "Incremented by one for every store sent to Level-2 (L1.5) cache"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z13/basic.json +1 -1
index 2dd8dafff2ef..783de7f1aeaa 100644
@@ -82,5 +82,5 @@
 		"EventName": "PROBLEM_STATE_L1D_PENALTY_CYCLES",
 		"BriefDescription": "Problem-State L1D Penalty Cycles",
 		"PublicDescription": "Problem-State Level-1 D-Cache Penalty Cycle Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z13/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z13/extended.json +1 -1
index 5da8296b667e..1a5e4f89c57e 100644
@@ -390,5 +390,5 @@
 		"EventName": "MT_DIAG_CYCLES_TWO_THR_ACTIVE",
 		"BriefDescription": "Cycle count with two threads active",
 		"PublicDescription": "Cycle count with two threads active"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z14/basic.json +1 -1
index 17fb5241928b..fc762e9f1d6e 100644
@@ -54,5 +54,5 @@
 		"EventName": "PROBLEM_STATE_INSTRUCTIONS",
 		"BriefDescription": "Problem-State Instructions",
 		"PublicDescription": "Problem-State Instruction Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z14/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z14/extended.json +1 -1
index 89e070727e1b..4942b20a1ea1 100644
@@ -369,5 +369,5 @@
 		"EventName": "MT_DIAG_CYCLES_TWO_THR_ACTIVE",
 		"BriefDescription": "Cycle count with two threads active",
 		"PublicDescription": "Cycle count with two threads active"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z15/basic.json +1 -1
index 17fb5241928b..fc762e9f1d6e 100644
@@ -54,5 +54,5 @@
 		"EventName": "PROBLEM_STATE_INSTRUCTIONS",
 		"BriefDescription": "Problem-State Instructions",
 		"PublicDescription": "Problem-State Instruction Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z15/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z15/crypto6.json +1 -1
index c998e4f1d1d2..ad79189050a0 100644
@@ -26,5 +26,5 @@
 		"EventName": "ECC_BLOCKED_CYCLES_COUNT",
 		"BriefDescription": "ECC Blocked Cycles Count",
 		"PublicDescription": "This counter counts the total number of CPU cycles blocked for the elliptic-curve cryptography (ECC) functions issued by the CPU because the ECC coprocessor is busy performing a function issued by another CPU."
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z15/extended.json +1 -1
index 24c4ba2a9ae5..8ac61f8f286b 100644
@@ -397,5 +397,5 @@
 		"EventName": "MT_DIAG_CYCLES_TWO_THR_ACTIVE",
 		"BriefDescription": "Cycle count with two threads active",
 		"PublicDescription": "Cycle count with two threads active"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z196/basic.json +1 -1
index 2dd8dafff2ef..783de7f1aeaa 100644
@@ -82,5 +82,5 @@
 		"EventName": "PROBLEM_STATE_L1D_PENALTY_CYCLES",
 		"BriefDescription": "Problem-State L1D Penalty Cycles",
 		"PublicDescription": "Problem-State Level-1 D-Cache Penalty Cycle Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z196/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_z196/extended.json +1 -1
index b7b42a870bb0..86b29fd181cf 100644
@@ -166,5 +166,5 @@
 		"EventName": "L1I_OFFCHIP_L3_SOURCED_WRITES",
 		"BriefDescription": "L1I Off-Chip L3 Sourced Writes",
 		"PublicDescription": "A directory write to the Level-1 I-Cache directory where the returned cache line was sourced from an Off Chip/On Book Level-3 cache"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_zec12/basic.json +1 -1
index 2dd8dafff2ef..783de7f1aeaa 100644
@@ -82,5 +82,5 @@
 		"EventName": "PROBLEM_STATE_L1D_PENALTY_CYCLES",
 		"BriefDescription": "Problem-State L1D Penalty Cycles",
 		"PublicDescription": "Problem-State Level-1 D-Cache Penalty Cycle Count"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_zec12/crypto.json +1 -1
index db286f19e7b6..3f28007d3892 100644
@@ -110,5 +110,5 @@
 		"EventName": "AES_BLOCKED_CYCLES",
 		"BriefDescription": "AES Blocked Cycles",
 		"PublicDescription": "Total number of CPU cycles blocked for the AES functions issued by the CPU because the DEA/AES coprocessor is busy performing a function issued by another CPU"
-	},
+	}
 ]
tools/perf/pmu-events/arch/s390/cf_zec12/extended.json +1 -1
index 162251037219..f40cbed89418 100644
@@ -243,5 +243,5 @@
 		"EventName": "TX_C_TABORT_SPECIAL",
 		"BriefDescription": "Aborted transactions in constrained TX mode using special completion logic",
 		"PublicDescription": "A transaction abort has occurred in a constrained transactional-execution mode and the CPU is using special logic to allow the transaction to complete"
-	},
+	}
 ]
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json +1 -1
index 788766f45dbc..73089c682f80 100644
@@ -38,5 +38,5 @@
 	    "BriefDescription": "Total cache hits",
 	    "PublicDescription": "Total cache hits",
 	    "Unit": "imc"
-  },
+  }
 ]
tools/perf/pmu-events/arch/x86/icelakex/icx-metrics.json +1 -1
index 57ddbb9f9b31..14b9a8ab15b9 100644
@@ -311,5 +311,5 @@
         "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
         "MetricGroup": "Power",
         "MetricName": "C6_Pkg_Residency"
-    },
+    }
 ]
Signature · 1 line
2.28.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] perf vendor-events: Fix all remaining invalid JSON files

Quoted 26 lines · James Clark

Remove trailing commas. A later commit will make the parser more strict and these will not be valid anymore.

---
  .../arch/arm64/ampere/emag/bus.json           |  2 +-
  .../arch/arm64/ampere/emag/cache.json         | 20 +++++++++----------
  .../arch/arm64/ampere/emag/clock.json         |  2 +-
  .../arch/arm64/ampere/emag/exception.json     |  4 ++--
  .../arch/arm64/ampere/emag/instruction.json   | 10 +++++-----
  .../arch/arm64/ampere/emag/memory.json        |  4 ++--
  .../arch/arm64/hisilicon/hip08/metrics.json   |  2 +-
  .../pmu-events/arch/nds32/n13/atcpmu.json     |  2 +-
  .../pmu-events/arch/s390/cf_z10/basic.json    |  2 +-
  .../pmu-events/arch/s390/cf_z10/crypto.json   |  2 +-
  .../pmu-events/arch/s390/cf_z10/extended.json |  2 +-
  .../pmu-events/arch/s390/cf_z13/basic.json    |  2 +-
  .../pmu-events/arch/s390/cf_z13/crypto.json   |  2 +-
  .../pmu-events/arch/s390/cf_z13/extended.json |  2 +-
  .../pmu-events/arch/s390/cf_z14/basic.json    |  2 +-
  .../pmu-events/arch/s390/cf_z14/crypto.json   |  2 +-
  .../pmu-events/arch/s390/cf_z14/extended.json |  2 +-
  .../pmu-events/arch/s390/cf_z15/basic.json    |  2 +-
  .../pmu-events/arch/s390/cf_z15/crypto.json   |  2 +-
  .../pmu-events/arch/s390/cf_z15/crypto6.json  |  2 +-
  .../pmu-events/arch/s390/cf_z15/extended.json |  2 +-
Quoted 8 lines
  .../pmu-events/arch/s390/cf_z196/basic.json   |  2 +-
  .../pmu-events/arch/s390/cf_z196/crypto.json  |  2 +-
  .../arch/s390/cf_z196/extended.json           |  2 +-
  .../pmu-events/arch/s390/cf_zec12/basic.json  |  2 +-
  .../pmu-events/arch/s390/cf_zec12/crypto.json |  2 +-
  .../arch/s390/cf_zec12/extended.json          |  2 +-
  .../arch/test/test_soc/cpu/uncore.json        |  2 +-
  .../arch/x86/icelakex/icx-metrics.json        |  2 +-

This seems fine. But, as mentioned earlier, I do worry that some of these JSONs are copied from some downstream repositories, and now they will go out of sync. That could cause problems, so need to check with respective owners.

Apart from that caveat, it seems ok:

#3 lore raw

PATCH 2/3 perf tools: Make the JSON parser more conformant when in strict mode

In reply to James Clark

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
tools/perf/pmu-events/jsmn.c +40 -2
index 11d1fa18bfa5..8124d2d3ff0c 100644
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT
+	/*
+	 * Keeps track of whether a new object/list/primitive is expected. New items are only
+	 * allowed after an opening brace, comma or colon. A closing brace after a comma is not
+	 * valid JSON.
+	 */
+	int expecting_item = 1;
+#endif
 
 	for (; parser->pos < len; parser->pos++) {
 		char c;
@@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		switch (c) {
 		case '{':
 		case '[':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			token = jsmn_alloc_token(parser, tokens, num_tokens);
 			if (token == NULL)
 				return JSMN_ERROR_NOMEM;
@@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			break;
 		case '}':
 		case ']':
+#ifdef JSMN_STRICT
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
 			for (i = parser->toknext - 1; i >= 0; i--) {
 				token = &tokens[i];
@@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			}
 			break;
 		case '\"':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_string(parser, js, len, tokens,
 					      num_tokens);
 			if (r < 0)
@@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case '\t':
 		case '\r':
 		case '\n':
-		case ':':
-		case ',':
 		case ' ':
 			break;
 #ifdef JSMN_STRICT
+		case ':':
+		case ',':
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 1;
+			break;
 			/*
 			 * In strict mode primitives are:
 			 * numbers and booleans.
@@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case 'f':
 		case 'n':
 #else
+		case ':':
+		case ',':
+			break;
 			/*
 			 * In non-strict mode every unquoted value
 			 * is a primitive.
@@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			/*FALL THROUGH */
 		default:
 #endif
+
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_primitive(parser, js, len, tokens,
 						 num_tokens);
 			if (r < 0)
@@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			return JSMN_ERROR_PART;
 	}
 
+#ifdef JSMN_STRICT
+	return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS;
+#else
 	return JSMN_SUCCESS;
+#endif
 }
 
 /*
Signature · 1 line
2.28.0
#4 lore raw

Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode

Quoted 14 lines · James Clark

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
tools/perf/pmu-events/jsmn.c +0 -0
index 11d1fa18bfa5..8124d2d3ff0c 100644

tools/perf/pmu-events/jsmn.c jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, · line 179

Quoted 4 lines
tools/perf/pmu-events/jsmn.c +1 -0
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT

I might have missed some discussion on this, but do we need the JSMN_STRICT define, if you enable it in the next patch? why can't we be more strict by default.. do you plan to disable it in future?

thanks,
jirka

Quoted 100 lines
tools/perf/pmu-events/jsmn.c +39 -2
+	/*
+	 * Keeps track of whether a new object/list/primitive is expected. New items are only
+	 * allowed after an opening brace, comma or colon. A closing brace after a comma is not
+	 * valid JSON.
+	 */
+	int expecting_item = 1;
+#endif
 
 	for (; parser->pos < len; parser->pos++) {
 		char c;
@@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		switch (c) {
 		case '{':
 		case '[':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			token = jsmn_alloc_token(parser, tokens, num_tokens);
 			if (token == NULL)
 				return JSMN_ERROR_NOMEM;
@@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			break;
 		case '}':
 		case ']':
+#ifdef JSMN_STRICT
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
 			for (i = parser->toknext - 1; i >= 0; i--) {
 				token = &tokens[i];
@@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			}
 			break;
 		case '\"':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_string(parser, js, len, tokens,
 					      num_tokens);
 			if (r < 0)
@@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case '\t':
 		case '\r':
 		case '\n':
-		case ':':
-		case ',':
 		case ' ':
 			break;
 #ifdef JSMN_STRICT
+		case ':':
+		case ',':
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 1;
+			break;
 			/*
 			 * In strict mode primitives are:
 			 * numbers and booleans.
@@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case 'f':
 		case 'n':
 #else
+		case ':':
+		case ',':
+			break;
 			/*
 			 * In non-strict mode every unquoted value
 			 * is a primitive.
@@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			/*FALL THROUGH */
 		default:
 #endif
+
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_primitive(parser, js, len, tokens,
 						 num_tokens);
 			if (r < 0)
@@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			return JSMN_ERROR_PART;
 	}
 
+#ifdef JSMN_STRICT
+	return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS;
+#else
 	return JSMN_SUCCESS;
+#endif
 }
 
 /*
Signature · 1 line
2.28.0
#5 lore raw

Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode

Quoted 10 lines · Jiri Olsa
Quoted 9 lines · James Clark

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
Quoted 14 lines

tools/perf/pmu-events/jsmn.c jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, · line 179

Quoted 9 lines
tools/perf/pmu-events/jsmn.c +1 -0
index 11d1fa18bfa5..8124d2d3ff0c 100644
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT

I might have missed some discussion on this, but do we need the JSMN_STRICT define, if you enable it in the next patch? why can't we be more strict by default.. do you plan to disable it in future?

I didn't plan on disabling it, I was just trying to keep to the existing style of the jsmn project.

I could have added the trailing comma detection by default and not inside any #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it enables some additional built in checking that was already there. So I thought it made sense to put my new strict stuff inside the existing strict option.

One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks and have everything strict by default. But it would be a further deviation from jsmn.

Thanks
James

Quoted 105 lines

thanks,
jirka

Quoted 100 lines
tools/perf/pmu-events/jsmn.c +39 -2
+	/*
+	 * Keeps track of whether a new object/list/primitive is expected. New items are only
+	 * allowed after an opening brace, comma or colon. A closing brace after a comma is not
+	 * valid JSON.
+	 */
+	int expecting_item = 1;
+#endif
 
 	for (; parser->pos < len; parser->pos++) {
 		char c;
@@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		switch (c) {
 		case '{':
 		case '[':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			token = jsmn_alloc_token(parser, tokens, num_tokens);
 			if (token == NULL)
 				return JSMN_ERROR_NOMEM;
@@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			break;
 		case '}':
 		case ']':
+#ifdef JSMN_STRICT
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
 			for (i = parser->toknext - 1; i >= 0; i--) {
 				token = &tokens[i];
@@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			}
 			break;
 		case '\"':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_string(parser, js, len, tokens,
 					      num_tokens);
 			if (r < 0)
@@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case '\t':
 		case '\r':
 		case '\n':
-		case ':':
-		case ',':
 		case ' ':
 			break;
 #ifdef JSMN_STRICT
+		case ':':
+		case ',':
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 1;
+			break;
 			/*
 			 * In strict mode primitives are:
 			 * numbers and booleans.
@@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case 'f':
 		case 'n':
 #else
+		case ':':
+		case ',':
+			break;
 			/*
 			 * In non-strict mode every unquoted value
 			 * is a primitive.
@@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			/*FALL THROUGH */
 		default:
 #endif
+
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_primitive(parser, js, len, tokens,
 						 num_tokens);
 			if (r < 0)
@@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			return JSMN_ERROR_PART;
 	}
 
+#ifdef JSMN_STRICT
+	return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS;
+#else
 	return JSMN_SUCCESS;
+#endif
 }
 
 /*
Signature · 1 line
2.28.0
Acked-by
#6 lore raw

Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode

Quoted 31 lines · James Clark
Quoted 10 lines · Jiri Olsa
Quoted 9 lines · James Clark

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
Quoted 14 lines

tools/perf/pmu-events/jsmn.c jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, · line 179

Quoted 9 lines
tools/perf/pmu-events/jsmn.c +1 -0
index 11d1fa18bfa5..8124d2d3ff0c 100644
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT

I might have missed some discussion on this, but do we need the JSMN_STRICT define, if you enable it in the next patch? why can't we be more strict by default.. do you plan to disable it in future?

I didn't plan on disabling it, I was just trying to keep to the existing style of the jsmn project.

Quoted 7 lines

I could have added the trailing comma detection by default and not inside any #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it enables some additional built in checking that was already there. So I thought it made sense to put my new strict stuff inside the existing strict option.

One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks and have everything strict by default. But it would be a further deviation from jsmn.

ok, I think it makes sense to have JSMN_STRICT then.. thanks for explanation

jirka

Quoted 110 lines

Thanks
James

Quoted 105 lines

thanks,
jirka

Quoted 100 lines
tools/perf/pmu-events/jsmn.c +39 -2
+	/*
+	 * Keeps track of whether a new object/list/primitive is expected. New items are only
+	 * allowed after an opening brace, comma or colon. A closing brace after a comma is not
+	 * valid JSON.
+	 */
+	int expecting_item = 1;
+#endif
 
 	for (; parser->pos < len; parser->pos++) {
 		char c;
@@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		switch (c) {
 		case '{':
 		case '[':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			token = jsmn_alloc_token(parser, tokens, num_tokens);
 			if (token == NULL)
 				return JSMN_ERROR_NOMEM;
@@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			break;
 		case '}':
 		case ']':
+#ifdef JSMN_STRICT
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
 			for (i = parser->toknext - 1; i >= 0; i--) {
 				token = &tokens[i];
@@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			}
 			break;
 		case '\"':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_string(parser, js, len, tokens,
 					      num_tokens);
 			if (r < 0)
@@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case '\t':
 		case '\r':
 		case '\n':
-		case ':':
-		case ',':
 		case ' ':
 			break;
 #ifdef JSMN_STRICT
+		case ':':
+		case ',':
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 1;
+			break;
 			/*
 			 * In strict mode primitives are:
 			 * numbers and booleans.
@@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case 'f':
 		case 'n':
 #else
+		case ':':
+		case ',':
+			break;
 			/*
 			 * In non-strict mode every unquoted value
 			 * is a primitive.
@@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			/*FALL THROUGH */
 		default:
 #endif
+
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_primitive(parser, js, len, tokens,
 						 num_tokens);
 			if (r < 0)
@@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			return JSMN_ERROR_PART;
 	}
 
+#ifdef JSMN_STRICT
+	return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS;
+#else
 	return JSMN_SUCCESS;
+#endif
 }
 
 /*
Signature · 1 line
2.28.0
#7 lore raw

Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode

Em Fri, Oct 08, 2021 at 03:12:03PM +0200, Jiri Olsa escreveu:

Quoted 37 lines · James Clark
Quoted 36 lines · Jiri Olsa
Quoted 10 lines · James Clark
Quoted 9 lines

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
Quoted 14 lines

tools/perf/pmu-events/jsmn.c jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, · line 179

Quoted 9 lines
tools/perf/pmu-events/jsmn.c +1 -0
index 11d1fa18bfa5..8124d2d3ff0c 100644
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT

I might have missed some discussion on this, but do we need the JSMN_STRICT define, if you enable it in the next patch? why can't we be more strict by default.. do you plan to disable it in future?

I didn't plan on disabling it, I was just trying to keep to the existing style of the jsmn project.

I could have added the trailing comma detection by default and not inside any #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it enables some additional built in checking that was already there. So I thought it made sense to put my new strict stuff inside the existing strict option.

Quoted 7 lines
Quoted 2 lines

One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks and have everything strict by default. But it would be a further deviation from jsmn.

ok, I think it makes sense to have JSMN_STRICT then.. thanks for explanation

So, is this for the whole patchset? b4 picked it just for this message.

- Arnaldo

Quoted 112 lines

jirka

Quoted 110 lines

Thanks
James

Quoted 105 lines

thanks,
jirka

Quoted 100 lines
tools/perf/pmu-events/jsmn.c +39 -2
+	/*
+	 * Keeps track of whether a new object/list/primitive is expected. New items are only
+	 * allowed after an opening brace, comma or colon. A closing brace after a comma is not
+	 * valid JSON.
+	 */
+	int expecting_item = 1;
+#endif
 
 	for (; parser->pos < len; parser->pos++) {
 		char c;
@@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		switch (c) {
 		case '{':
 		case '[':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			token = jsmn_alloc_token(parser, tokens, num_tokens);
 			if (token == NULL)
 				return JSMN_ERROR_NOMEM;
@@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			break;
 		case '}':
 		case ']':
+#ifdef JSMN_STRICT
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+#endif
 			type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
 			for (i = parser->toknext - 1; i >= 0; i--) {
 				token = &tokens[i];
@@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			}
 			break;
 		case '\"':
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_string(parser, js, len, tokens,
 					      num_tokens);
 			if (r < 0)
@@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case '\t':
 		case '\r':
 		case '\n':
-		case ':':
-		case ',':
 		case ' ':
 			break;
 #ifdef JSMN_STRICT
+		case ':':
+		case ',':
+			if (expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 1;
+			break;
 			/*
 			 * In strict mode primitives are:
 			 * numbers and booleans.
@@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 		case 'f':
 		case 'n':
 #else
+		case ':':
+		case ',':
+			break;
 			/*
 			 * In non-strict mode every unquoted value
 			 * is a primitive.
@@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			/*FALL THROUGH */
 		default:
 #endif
+
+#ifdef JSMN_STRICT
+			if (!expecting_item)
+				return JSMN_ERROR_INVAL;
+			expecting_item = 0;
+#endif
 			r = jsmn_parse_primitive(parser, js, len, tokens,
 						 num_tokens);
 			if (r < 0)
@@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 			return JSMN_ERROR_PART;
 	}
 
+#ifdef JSMN_STRICT
+	return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS;
+#else
 	return JSMN_SUCCESS;
+#endif
 }
 
 /*
Signature · 1 line
2.28.0
Signature · 1 line
- Arnaldo
#8 lore raw

Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode

Em Fri, Oct 08, 2021 at 03:56:26PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 41 lines

Em Fri, Oct 08, 2021 at 03:12:03PM +0200, Jiri Olsa escreveu:

Quoted 40 lines · James Clark
Quoted 38 lines · Jiri Olsa
Quoted 10 lines · James Clark
Quoted 9 lines

Return an error when a trailing comma is found or a new item is encountered before a comma or an opening brace. This ensures that the perf json files conform more closely to the spec at https://www.json.org

---
 tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
Quoted 14 lines

tools/perf/pmu-events/jsmn.c jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, · line 179

Quoted 9 lines
tools/perf/pmu-events/jsmn.c +1 -0
index 11d1fa18bfa5..8124d2d3ff0c 100644
@@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
 	jsmnerr_t r;
 	int i;
 	jsmntok_t *token;
+#ifdef JSMN_STRICT

I might have missed some discussion on this, but do we need the JSMN_STRICT define, if you enable it in the next patch? why can't we be more strict by default.. do you plan to disable it in future?

I didn't plan on disabling it, I was just trying to keep to the existing style of the jsmn project.

I could have added the trailing comma detection by default and not inside any #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it enables some additional built in checking that was already there. So I thought it made sense to put my new strict stuff inside the existing strict option.

One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks and have everything strict by default. But it would be a further deviation from jsmn.

Quoted 6 lines
Quoted 4 lines

ok, I think it makes sense to have JSMN_STRICT then.. thanks for explanation

So, is this for the whole patchset? b4 picked it just for this message.

Got it from IRC, thanks,

- Arnaldo

#9 lore raw

PATCH 3/3 perf tools: Enable strict JSON parsing

In reply to James Clark

This is to ensure that the PMU event files can always be parsed by other tools.

Testing
=======

* There are no errors when parsing files for all architectures:

     # pmu-events/jevents nds32 pmu-events/arch/ test
     # pmu-events/jevents s390 pmu-events/arch/ test
     # pmu-events/jevents powerpc pmu-events/arch/ test
     # pmu-events/jevents arm64 pmu-events/arch/ test
     # pmu-events/jevents test pmu-events/arch/ test
     # pmu-events/jevents x86 pmu-events/arch/ test

* Trailing and leading commas now cause a parse error

* Double commas now cause a parse error

* Compilation and parsing works with strict mode disabled and enabled

* A diff of the output files shows no changes

---
 tools/perf/pmu-events/jsmn.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/pmu-events/jsmn.c +1 -0
index 8124d2d3ff0c..831dc44c4558 100644
@@ -24,6 +24,7 @@
 
 #include <stdlib.h>
 #include "jsmn.h"
+#define JSMN_STRICT
 
 /*
  * Allocates a fresh unused token from the token pool.
Signature · 1 line
2.28.0
Reviewed-by on the v1 series
#10 lore raw
In reply to James Clark
Quoted 6 lines · James Clark

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Looks good to me.  The Intel files are already generated by automated tools using the standard python JSON writer, I guess if it's out of sync someone must have edited it by hand. So it should be fine to fix it.

-Andi

#11 lore raw
In reply to James Clark
Quoted 9 lines · James Clark

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something.

I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string
make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

Thanks,
Kajol Jain

Quoted 38 lines

James Clark (3):
perf vendor-events: Fix all remaining invalid JSON files perf tools: Make the JSON parser more conformant when in strict mode perf tools: Enable strict JSON parsing

 .../arch/arm64/ampere/emag/bus.json           |  2 +-
 .../arch/arm64/ampere/emag/cache.json         | 20 ++++-----
 .../arch/arm64/ampere/emag/clock.json         |  2 +-
 .../arch/arm64/ampere/emag/exception.json     |  4 +-
 .../arch/arm64/ampere/emag/instruction.json   | 10 ++---
 .../arch/arm64/ampere/emag/memory.json        |  4 +-
 .../arch/arm64/hisilicon/hip08/metrics.json   |  2 +-
 .../pmu-events/arch/nds32/n13/atcpmu.json     |  2 +-
 .../pmu-events/arch/s390/cf_z10/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z10/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z10/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z13/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z13/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z13/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z14/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z14/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z14/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z15/basic.json    |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto.json   |  2 +-
 .../pmu-events/arch/s390/cf_z15/crypto6.json  |  2 +-
 .../pmu-events/arch/s390/cf_z15/extended.json |  2 +-
 .../pmu-events/arch/s390/cf_z196/basic.json   |  2 +-
 .../pmu-events/arch/s390/cf_z196/crypto.json  |  2 +-
 .../arch/s390/cf_z196/extended.json           |  2 +-
 .../pmu-events/arch/s390/cf_zec12/basic.json  |  2 +-
 .../pmu-events/arch/s390/cf_zec12/crypto.json |  2 +-
 .../arch/s390/cf_zec12/extended.json          |  2 +-
 .../arch/test/test_soc/cpu/uncore.json        |  2 +-
 .../arch/x86/icelakex/icx-metrics.json        |  2 +-
 tools/perf/pmu-events/jsmn.c                  | 43 ++++++++++++++++++-
 30 files changed, 85 insertions(+), 46 deletions(-)
#12 lore raw
Quoted 13 lines · kajoljain
Quoted 9 lines · James Clark

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Quoted 8 lines

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something>
I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string

Hi Kajol,

A trailing comma was fixed in this file 3 weeks ago at b8b350a. Can you confirm if you have updated to get this commit on perf core?

Alternately you could pull from my branch above which is up to date enough to include it.

The file is in pmu-events/arch/test/ so I would expect it to fail on all platforms.

Quoted 10 lines

make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

I can add a character number with the following fix if you think that would be good enough? A line number might be a bigger change and involve keeping track of newline characters.

tools/perf/pmu-events/json.c +1 -1
index 0544398d6e2d..41a14e1543bf 100644
@@ -99,7 +99,7 @@ jsmntok_t *parse_json(const char *fn, char **map, size_t *size, int *len)
        res = jsmn_parse(&parser, *map, *size, tokens,
                         sz / sizeof(jsmntok_t));
        if (res != JSMN_SUCCESS) {
-               pr_err("%s: json error %s\n", fn, jsmn_strerror(res));
+               pr_err("%s: json error at character %u '%s'\n", fn, parser.pos, jsmn_strerror(res));
                goto error_free;
        }
        if (len)

It prints this for the same error you have above:

pmu-events/arch/test/test_soc/sys/uncore.json: json error at character 213 'Invalid character inside JSON string'

Although funnily enough after re-introducing that extra comma it doesn't fail the build for me, it just prints the error message. But I may have noticed some dependency tracking issues around the json files.

James

#13 lore raw
Quoted 25 lines · James Clark
Quoted 13 lines · kajoljain
Quoted 9 lines · James Clark

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Quoted 8 lines

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something>
I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string

Quoted 7 lines

Hi Kajol,

A trailing comma was fixed in this file 3 weeks ago at b8b350a. Can you confirm if you have updated to get this commit on perf core?

Alternately you could pull from my branch above which is up to date enough to include it.

Hi James,
Thanks for pointing it. Not getting build issue now.

Quoted 10 lines

The file is in pmu-events/arch/test/ so I would expect it to fail on all platforms.

Quoted 7 lines

make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Quoted 7 lines
Quoted 3 lines

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

I can add a character number with the following fix if you think that would be good enough? A line number might be a bigger change and involve keeping track of newline characters.

Sure. I think then we can skip this change. Not sure if character number will be helpful.

Patch-set looks good to me.

Reviewed-by Kajol Jain<[email protected]>

Thanks,
Kajol Jain

Quoted 25 lines
tools/perf/pmu-events/json.c +1 -1
index 0544398d6e2d..41a14e1543bf 100644
@@ -99,7 +99,7 @@ jsmntok_t *parse_json(const char *fn, char **map, size_t *size, int *len)
        res = jsmn_parse(&parser, *map, *size, tokens,
                         sz / sizeof(jsmntok_t));
        if (res != JSMN_SUCCESS) {
-               pr_err("%s: json error %s\n", fn, jsmn_strerror(res));
+               pr_err("%s: json error at character %u '%s'\n", fn, parser.pos, jsmn_strerror(res));
                goto error_free;
        }
        if (len)

It prints this for the same error you have above> pmu-events/arch/test/test_soc/sys/uncore.json: json error at character 213 'Invalid character inside JSON string'

Although funnily enough after re-introducing that extra comma it doesn't fail the build for me, it just prints the error message. But I may have noticed some dependency tracking issues around the json files.

James

#14 lore raw

Em Fri, Oct 08, 2021 at 04:56:55PM +0530, kajoljain escreveu:

Quoted 56 lines · James Clark
Quoted 25 lines · kajoljain
Quoted 13 lines · James Clark
Quoted 9 lines

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Quoted 8 lines

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something>
I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string

Quoted 7 lines

Hi Kajol,

A trailing comma was fixed in this file 3 weeks ago at b8b350a. Can you confirm if you have updated to get this commit on perf core?

Alternately you could pull from my branch above which is up to date enough to include it.

Hi James,
Thanks for pointing it. Not getting build issue now.

Quoted 10 lines

The file is in pmu-events/arch/test/ so I would expect it to fail on all platforms.

Quoted 7 lines

make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Quoted 7 lines
Quoted 3 lines

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

I can add a character number with the following fix if you think that would be good enough? A line number might be a bigger change and involve keeping track of newline characters.

Quoted 6 lines

Sure. I think then we can skip this change. Not sure if character number will be helpful.

Patch-set looks good to me.

Reviewed-by Kajol Jain<[email protected]>

Applied ok as-is to my perf/core branch, applied and added your Reviewed-by, thanks.

- Arnaldo

Quoted 28 lines

Thanks,
Kajol Jain

Quoted 25 lines
tools/perf/pmu-events/json.c +1 -1
index 0544398d6e2d..41a14e1543bf 100644
@@ -99,7 +99,7 @@ jsmntok_t *parse_json(const char *fn, char **map, size_t *size, int *len)
        res = jsmn_parse(&parser, *map, *size, tokens,
                         sz / sizeof(jsmntok_t));
        if (res != JSMN_SUCCESS) {
-               pr_err("%s: json error %s\n", fn, jsmn_strerror(res));
+               pr_err("%s: json error at character %u '%s'\n", fn, parser.pos, jsmn_strerror(res));
                goto error_free;
        }
        if (len)

It prints this for the same error you have above> pmu-events/arch/test/test_soc/sys/uncore.json: json error at character 213 'Invalid character inside JSON string'

Although funnily enough after re-introducing that extra comma it doesn't fail the build for me, it just prints the error message. But I may have noticed some dependency tracking issues around the json files.

James

Signature · 1 line
- Arnaldo
#15 lore raw
Quoted 60 lines · Arnaldo Carvalho de Melo

Em Fri, Oct 08, 2021 at 04:56:55PM +0530, kajoljain escreveu:

Quoted 59 lines · James Clark
Quoted 25 lines · kajoljain
Quoted 13 lines · James Clark
Quoted 9 lines

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Quoted 8 lines

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something>
I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string

Quoted 7 lines

Hi Kajol,

A trailing comma was fixed in this file 3 weeks ago at b8b350a. Can you confirm if you have updated to get this commit on perf core?

Alternately you could pull from my branch above which is up to date enough to include it.

Hi James,
Thanks for pointing it. Not getting build issue now.

Quoted 10 lines

The file is in pmu-events/arch/test/ so I would expect it to fail on all platforms.

Quoted 7 lines

make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Quoted 7 lines
Quoted 3 lines

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

I can add a character number with the following fix if you think that would be good enough? A line number might be a bigger change and involve keeping track of newline characters.

Sure. I think then we can skip this change. Not sure if character number will be helpful.

Quoted 7 lines
Quoted 3 lines

Patch-set looks good to me.

Reviewed-by Kajol Jain<[email protected]>

Applied ok as-is to my perf/core branch, applied and added your Reviewed-by, thanks.

Thanks Arnaldo. This does mean that the arm64 build will fail until "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" is applied. I think there is also an arm64 build issue with "[PATCH 02/21] perf
pmu: Add const to pmu_events_map." which Andrew Kilroy has replied to.

James

#16 lore raw
Quoted 67 lines · James Clark
Quoted 64 lines · Arnaldo Carvalho de Melo

Em Fri, Oct 08, 2021 at 04:56:55PM +0530, kajoljain escreveu:

Quoted 62 lines · James Clark
Quoted 25 lines · kajoljain
Quoted 13 lines · James Clark
Quoted 9 lines

After a discussion on "[PATCH 1/4] perf vendor events: Syntax corrections in Neoverse N1 json", John Garry suggested that we can just modify the parser to make it more strict. Hopefully this will remove the need to apply any future JSON comma fixup commits.

Applies on top of "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" on perf/core.

Also available at:
git clone --branch james-json-parse-fix [email protected]:linux-arm/linux-jc.git

Quoted 8 lines

Hi James,
Do we have any dependency patches on top of this patch series. I am
reviewing and testing it, but in both powerpc and x86 system I am getting build issue. Not sure if I am missing something>
I am trying your changes on top of upstream perf.

pmu-events/arch/test/test_soc/sys/uncore.json: json error Invalid character inside JSON string

Quoted 7 lines

Hi Kajol,

A trailing comma was fixed in this file 3 weeks ago at b8b350a. Can you confirm if you have updated to get this commit on perf core?

Alternately you could pull from my branch above which is up to date enough to include it.

Hi James,
Thanks for pointing it. Not getting build issue now.

Quoted 10 lines

The file is in pmu-events/arch/test/ so I would expect it to fail on all platforms.

Quoted 7 lines

make[3]: *** [pmu-events/Build:18: pmu-events/pmu-events.c] Error 1 make[3]: *** Deleting file 'pmu-events/pmu-events.c' make[2]: *** [Makefile.perf:667: pmu-events/pmu-events-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Quoted 7 lines
Quoted 3 lines

Also, Is it possible to add line number along with file name while showing this error json error Invalid character inside JSON string. It might make it easy to fix.

I can add a character number with the following fix if you think that would be good enough? A line number might be a bigger change and involve keeping track of newline characters.

Sure. I think then we can skip this change. Not sure if character number will be helpful.

Patch-set looks good to me.

Reviewed-by Kajol Jain<[email protected]>

Quoted 9 lines
Quoted 3 lines

Applied ok as-is to my perf/core branch, applied and added your Reviewed-by, thanks.

Thanks Arnaldo. This does mean that the arm64 build will fail until "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" is applied. I think there is also an arm64 build issue with "[PATCH 02/21] perf
pmu: Add const to pmu_events_map." which Andrew Kilroy has replied to.

Ok, this will hopefully change tomorrow after today's Brazilian holiday when I get to process that series,

Thanks,

- Arnaldo

#17 lore raw
In reply to James Clark

Em Tue, Oct 12, 2021 at 02:30:51PM +0100, James Clark escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 9 lines

Em Fri, Oct 08, 2021 at 04:56:55PM +0530, kajoljain escreveu:

Quoted 8 lines · James Clark
Quoted 1 line · kajoljain

Sure. I think then we can skip this change. Not sure if character number will be helpful.

Patch-set looks good to me.

Reviewed-by Kajol Jain<[email protected]>

Quoted 7 lines
Quoted 2 lines

Applied ok as-is to my perf/core branch, applied and added your Reviewed-by, thanks.

Thanks Arnaldo. This does mean that the arm64 build will fail until "[PATCH v2 1/3] perf vendor events: Syntax corrections in Neoverse N1 json" is applied. I think there is also an arm64 build issue with "[PATCH 02/21] perf
pmu: Add const to pmu_events_map." which Andrew Kilroy has replied to.

Its all in:

19f8408a634c9515 (HEAD -> perf/core) perf intel-pt: Add support for PERF_RECORD_AUX_OUTPUT_HW_ID 69125e749c006b4f perf tools: Add support for PERF_RECORD_AUX_OUTPUT_HW_ID 1b1d9560a61f1e4e perf vendor events arm64: Categorise the Neoverse V1 counters abe8733bc3575869 perf vendor events arm64: Add new armv8 pmu events d211e9e76a466cce perf vendor events: Syntax corrections in Neoverse N1 json c067335fcbfc67c3 (quaco/perf/core, acme/tmp.perf/core) perf metric: Allow modifiers on metrics. acf2cb9cf242e9ab perf parse-events: Identify broken modifiers
fb193eca0ae8ddae perf metric: Switch fprintf() to pr_err()
fb8c3a06943cc3c7 perf metrics: Modify setup and deduplication
4965bb2e71371d5f perf expr: Add subset utility
c1d7cd1b36fce16b perf metric: Encode and use metric-id as qualifier 3743f880b3856971 perf parse-events: Allow config on kernel PMU events 844f07a5ddcd46c5 perf parse-events: Add new "metric-id" term
e68f07424b8b3f00 perf parse-events: Add const to evsel name
ace154d9f5dc3331 perf metric: Simplify metric_refs calculation
eeffd53b41dc7077 perf metric: Document the internal 'struct metric' 9aa64400defa07fb perf metric: Comment data structures
353ce4ed869635c7 perf metric: Modify resolution and recursion check 0bffecb0ac304bb2 perf metric: Only add a referenced metric once
937323c22db4cb1e perf metric: Add metric new and free
176b9da84871449d perf metric: Add documentation and rename a variable. cc6803c12cef80f1 perf metric: Move runtime value to the expr context 9610bca8f117d963 perf pmu: Make pmu_event tables const
95ed79343835656d perf pmu: Make pmu_sys_event_tables const
05335f28549c7cc5 perf pmu: Add const to pmu_events_map.
cac98c8aca3c7dd2 tools lib: Adopt list_sort from the kernel sources f792cf8a094eac29 perf kmem: Improve man page for record options
eda1a84cb4e93759 perf tools: Enable strict JSON parsing
21813684e46df1c9 perf tools: Make the JSON parser more conformant when in strict mode 08f3e0873ac20344 perf vendor-events: Fix all remaining invalid JSON files

- Arnaldo