You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/06/18 18:41:40 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1271: Feature/syscall instrumentation

xiaoxiang781216 commented on a change in pull request #1271:
URL: https://github.com/apache/incubator-nuttx/pull/1271#discussion_r442412819



##########
File path: syscall/syscall_name.c
##########
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * syscall/syscall_name.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifndef CONFIG_LIB_SYSCALL
+#define CONFIG_LIB_SYSCALL
+#endif
+#include <syscall.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* System call name tables.  This table is indexed by the system call numbers
+ * defined above.  Given the system call number, this table provides the
+ * name of the corresponding system function.
+ */
+
+const char *g_syscallname[SYS_nsyscalls + 1] =

Review comment:
       Who will use g_syscallname?
   Should we change the name to g_funcnames and put the declaration into nuttx/include/sys/syscall.h like other variables?

##########
File path: tools/mksyscall.c
##########
@@ -450,6 +452,27 @@ static void generate_stub(int nfixed, int nparms)
 
   fprintf(stream, ")\n{\n");
 
+  /* Generate the result variable definition for non-void function */
+
+  if (strcmp(g_parm[RETTYPE_INDEX], "void") != 0)
+    {
+      fprintf(stream, "  uintptr_t result;\n\n");

Review comment:
       Let's always define result to simplify the code:
   ```
   uintptr_t result = 0;
   sched_note_syscall_enter(...);
   ...
   sched_note_syscall_leave(..., result);
   return result;
   ```

##########
File path: syscall/syscall_name.c
##########
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * syscall/syscall_name.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifndef CONFIG_LIB_SYSCALL
+#define CONFIG_LIB_SYSCALL
+#endif
+#include <syscall.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* System call name tables.  This table is indexed by the system call numbers
+ * defined above.  Given the system call number, this table provides the
+ * name of the corresponding system function.
+ */
+
+const char *g_syscallname[SYS_nsyscalls + 1] =
+{
+#  define SYSCALL_LOOKUP1(f,n) #f
+#  define SYSCALL_LOOKUP(f,n)  , #f
+#  include <sys/syscall_lookup.h>
+#  undef SYSCALL_LOOKUP1
+#  undef SYSCALL_LOOKUP
+  , 0

Review comment:
       Why need the null terminator?

##########
File path: syscall/Makefile
##########
@@ -76,27 +88,43 @@ $(BIN1): $(PROXY_OBJS)
 $(BIN2): $(STUB_OBJS)
 	$(call ARCHIVE, $@, $(STUB_OBJS))
 
+$(BIN3): $(WRAP_OBJS)
+	$(call ARCHIVE, $@, $(WRAP_OBJS))
+
+$(SYSCALLIST): .context
+
 .depend: Makefile $(SRCS)
-	$(Q) $(MKDEP) $(PROXYDEPPATH) $(STUBDEPPATH) \
+	$(Q) $(MKDEP) $(PROXYDEPPATH) $(STUBDEPPATH) $(WRAPDEPPATH) \
 	  "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
 	$(Q) touch $@
 
 depend: .depend
 
 .context: syscall.csv
 	$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksyscall
+ifeq ($(CONFIG_LIB_SYSCALL),y)
 	$(Q) (cd proxies; $(MKSYSCALL) -p $(CSVFILE);)
 	$(Q) (cd stubs; $(MKSYSCALL) -s $(CSVFILE);)
+else
+ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
+	$(Q) (cd wraps; $(MKSYSCALL) -w $(CSVFILE);)
+	$(Q) $(MKSYSCALL) -l $(CSVFILE) > $(SYSCALLLIST:.txt=.h)
+	$(Q) $(call PREPROCESS, $(SYSCALLLIST:.txt=.h), $(SYSCALLLIST))
+	$(Q) sed -i -n -e '/^[^#]/p' $(SYSCALLLIST)

Review comment:
       Why we need four steps to generate the link command file?
   ```
   $(Q) $(MKSYSCALL) -l $(CSVFILE) > $(SYSCALLLIST:.txt=.h)
   $(Q) $(call PREPROCESS, $(SYSCALLLIST:.txt=.h), $(SYSCALLLIST))
   $(Q) sed -i -n -e '/^[^#]/p' $(SYSCALLLIST)
   cat $< | sed -e 's/^/--wrap=/' > $@
   ```
   We can define a clever SYSCALL_LOOKUP macro to generate them in one step:
   ```
   --wrap=xxx
   --wrap=yyy
   ```
   then we don't add -l for mksyscall and postprocess again in arch's Makefile.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org