@@ -770,6 +770,10 @@ static int check_prepare_btf_string_fetch(char *typename,
770770
771771#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
772772
773+ /*
774+ * Add the entry code to store the 'argnum'th parameter and return the offset
775+ * in the entry data buffer where the data will be stored.
776+ */
773777static int __store_entry_arg (struct trace_probe * tp , int argnum )
774778{
775779 struct probe_entry_arg * earg = tp -> entry_arg ;
@@ -793,6 +797,20 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum)
793797 tp -> entry_arg = earg ;
794798 }
795799
800+ /*
801+ * The entry code array is repeating the pair of
802+ * [FETCH_OP_ARG(argnum)][FETCH_OP_ST_EDATA(offset of entry data buffer)]
803+ * and the rest of entries are filled with [FETCH_OP_END].
804+ *
805+ * To reduce the redundant function parameter fetching, we scan the entry
806+ * code array to find the FETCH_OP_ARG which already fetches the 'argnum'
807+ * parameter. If it doesn't match, update 'offset' to find the last
808+ * offset.
809+ * If we find the FETCH_OP_END without matching FETCH_OP_ARG entry, we
810+ * will save the entry with FETCH_OP_ARG and FETCH_OP_ST_EDATA, and
811+ * return data offset so that caller can find the data offset in the entry
812+ * data buffer.
813+ */
796814 offset = 0 ;
797815 for (i = 0 ; i < earg -> size - 1 ; i ++ ) {
798816 switch (earg -> code [i ].op ) {
@@ -826,6 +844,16 @@ int traceprobe_get_entry_data_size(struct trace_probe *tp)
826844 if (!earg )
827845 return 0 ;
828846
847+ /*
848+ * earg->code[] array has an operation sequence which is run in
849+ * the entry handler.
850+ * The sequence stopped by FETCH_OP_END and each data stored in
851+ * the entry data buffer by FETCH_OP_ST_EDATA. The FETCH_OP_ST_EDATA
852+ * stores the data at the data buffer + its offset, and all data are
853+ * "unsigned long" size. The offset must be increased when a data is
854+ * stored. Thus we need to find the last FETCH_OP_ST_EDATA in the
855+ * code array.
856+ */
829857 for (i = 0 ; i < earg -> size ; i ++ ) {
830858 switch (earg -> code [i ].op ) {
831859 case FETCH_OP_END :
0 commit comments