Git Product home page Git Product logo

Comments (11)

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024 4

sent

from uclibc-ng.

fallen avatar fallen commented on May 20, 2024

Hello,
Can you propose a patch?
Can you also explain better the issue? (copy paste of compiling line with compiler arguments and error message)

from uclibc-ng.

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024

Here is the example from allocatestack.c (lines 777-886, the inline function is at line 800), in the following function (I removed some code so that this reply would not be too long):

/* In case of a fork() call the memory allocation in the child will be
   the same but only one thread is running.  All stacks except that of
   the one running thread are not used anymore.  We have to recycle
   them.  */
void
__reclaim_stacks (void)
{
  struct pthread *self = (struct pthread *) THREAD_SELF;
    .
    .
    .
  if (in_flight_stack != 0)
    {
      bool add_p = in_flight_stack & 1;
      list_t *elem = (list_t *)(uintptr_t)(in_flight_stack & ~UINTMAX_C (1));

      if (add_p)
	{
	  /* We always add at the beginning of the list.  So in this
	     case we only need to check the beginning of these lists.  */
	  int check_list (list_t *l)
	  {
	    if (l->next->prev != l)
	      {
		assert (l->next->prev == elem);

		elem->next = l->next;
		elem->prev = l;
		l->next = elem;

		return 1;
	      }

	    return 0;
	  }

	  if (check_list (&stack_used) == 0)
	    (void) check_list (&stack_cache);
	}
      else
	{
	  /* We can simply always replay the delete operation.  */
	  elem->next->prev = elem->prev;
	  elem->prev->next = elem->next;
	}
    }
    .
    .
    .
}

The function int check_list(...) should be define outside of __reclaim_stacks. I would suggest changing it as follows:

  /* We always add at the beginning of the list.  So in this
     case we only need to check the beginning of these lists.  */
static inline int __attribute__((always_inline))
check_list (list_t *l, list_t **elemPtr)
  {
   list_t elem = *elemPtr;

    if (l->next->prev != l)
      {
	assert (l->next->prev == elem);

	elem->next = l->next;
	elem->prev = l;
	l->next = elem;

	return 1;
      }

    return 0;
  }

/* In case of a fork() call the memory allocation in the child will be
   the same but only one thread is running.  All stacks except that of
   the one running thread are not used anymore.  We have to recycle
   them.  */
void
__reclaim_stacks (void)
{
  struct pthread *self = (struct pthread *) THREAD_SELF;
    .
    .
    .
  if (in_flight_stack != 0)
    {
      bool add_p = in_flight_stack & 1;
      list_t *elem = (list_t *)(uintptr_t)(in_flight_stack & ~UINTMAX_C (1));

      if (add_p)
	{
	  if (check_list (&stack_used, &elem) == 0)
	    (void) check_list (&stack_cache, &elem);
	}
      else
	{
	  /* We can simply always replay the delete operation.  */
	  elem->next->prev = elem->prev;
	  elem->prev->next = elem->next;
	}
    }
    .
    .
    .
}

from uclibc-ng.

fallen avatar fallen commented on May 20, 2024

I guess this kind of change would be accepted easily.
Can you send a patch to the list?

from uclibc-ng.

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024

Also, there is another thing that would need to be changed. For the generation of header files from .sym files, clang complains about names with @ in them. The script gen-as-const.awk, generates a stream with symbols with @@@name@@@, @@@value@@@, and @@@end@@@. Eventually @@@name@@@ becomes #define, a dollar-sign $ in the value gets removed and @@@end@@@ is removed.

gen-as-const.awk should be changed to generate it stream from:

__asm__("@@@name@@@<constant-name>@@@value@@@%0@@@end@@@" " "i" ((long) sizeof(<structure-name>)));

to:

__asm__("#define <constant-name> %0" " "i" ((long) sizeof(<structure-name>)));

The compiler will be used to generate lines that look like the following:

        #define <constant-name> $<constant-value>

The $ needs to be removed. There will also be other lines in the output from the compile (particularly with clang), but the need to go as well. This change will work for both gcc and clang.

Finally, the -no-nonnull-compare qualifier is no longer value. It should be changed to -no-nonnull. This problem never really shows up, except when another warning or error is reported.

I hope this helps and is what you asked.

from uclibc-ng.

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024

Here is the pat\ch:

diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c
index 137979542..e7e0b4d8f 100644
--- a/libpthread/nptl/allocatestack.c
+++ b/libpthread/nptl/allocatestack.c
@@ -773,6 +773,25 @@ __make_stacks_executable (void **stack_endp)
   return err;
 }
 
+/* We always add at the beginning of the list.  So in this
+   case we only need to check the beginning of these lists.  */
+static inline int __attribute__((always_inline))
+check_list (list_t *l, list_t **elemPtr)
+{
+  list_t *elem = *elemPtr;
+  if (l->next->prev != l)
+    {
+      assert (l->next->prev == elem);
+
+      elem->next = l->next;
+      elem->prev = l;
+      l->next = elem;
+
+      return 1;
+    }
+
+  return 0;
+}
 
 /* In case of a fork() call the memory allocation in the child will be
    the same but only one thread is running.  All stacks except that of
@@ -794,26 +813,8 @@ __reclaim_stacks (void)
 
       if (add_p)
 	{
-	  /* We always add at the beginning of the list.  So in this
-	     case we only need to check the beginning of these lists.  */
-	  int check_list (list_t *l)
-	  {
-	    if (l->next->prev != l)
-	      {
-		assert (l->next->prev == elem);
-
-		elem->next = l->next;
-		elem->prev = l;
-		l->next = elem;
-
-		return 1;
-	      }
-
-	    return 0;
-	  }
-
-	  if (check_list (&stack_used) == 0)
-	    (void) check_list (&stack_cache);
+	  if (check_list (&stack_used, &elem) == 0)
+	    (void) check_list (&stack_cache, &elem);
 	}
       else
 	{

from uclibc-ng.

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024

I found a couple of other issues, with clang. For one, it does not like hints on jne ASM statements. For example:

jne,pt 10f

Clang complains about the ,pt. Since this is just a hint, it can be removed. The only place that has these is in the libpthread/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S, at lines 85 and 122.

from uclibc-ng.

fallen avatar fallen commented on May 20, 2024

Could you send the patch to the mailing list? [email protected]
You can generate the patch using git format-patch and then send it using git send-email

According to the ",pt" hint, it seems this is not interpreted at all (nop) on post Pentium-4 CPU. So it seems useless and also increases binary size.
I guess removal of such hints could be a good idea.

from uclibc-ng.

JonathanBelanger avatar JonathanBelanger commented on May 20, 2024

Will you be rolling it into this repository?

from uclibc-ng.

fallen avatar fallen commented on May 20, 2024

I don't have the commit bit on this repo.
Usual way to get something integrated here is to post a patch using git send-email to the mailing list.
The more the patch is explained in the commit message (why this is needed, what it fixes etc), the more chance it has to get integrated (quickly).

from uclibc-ng.

fallen avatar fallen commented on May 20, 2024

It seems your email never got through to the list, according to the archives: https://mailman.uclibc-ng.org/pipermail/devel/
Maybe you need to first sign up and then re-send it?

from uclibc-ng.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.