<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>195439</bug_id>
          
          <creation_ts>2019-03-07 15:56:00 -0800</creation_ts>
          <short_desc>[PlayStation] Increase the default pthread stack size</short_desc>
          <delta_ts>2024-04-19 08:39:20 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Platform</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Christopher Reid">chris.reid</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>benjamin</cc>
    
    <cc>cdumez</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>dbates</cc>
    
    <cc>don.olmstead</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>fujii</cc>
    
    <cc>mark.lam</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1513762</commentid>
    <comment_count>0</comment_count>
    <who name="Christopher Reid">chris.reid</who>
    <bug_when>2019-03-07 15:56:00 -0800</bug_when>
    <thetext>Our PlayStation platform has a very small stack size of 64 KB for new threads. With default jsc VM options, web workers would instantly stack overflow on a 64 KB stack.
The main thread stack size is more reasonable at 2 MB.
This has came up before with https://bugs.webkit.org/show_bug.cgi?id=40103.

I tested with these jsc VM options:
maxPerThreadStackUsage = 64 * KB
softReservedZoneSize = 32 * KB
reservedZoneSize = 16 * KB

On linux with those options and `ulimit -s 64`, I ran javascriptcore-tests --memory-limited and there are still about 1,000 failures out of 55,000 tests.
There&apos;s 67 failures using `ulimit -s 512` and default VM options. 512 KB seems to also match the secondary thread stack size on iOS and Mac.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513785</commentid>
    <comment_count>1</comment_count>
      <attachid>363951</attachid>
    <who name="Christopher Reid">chris.reid</who>
    <bug_when>2019-03-07 16:18:37 -0800</bug_when>
    <thetext>Created attachment 363951
patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513786</commentid>
    <comment_count>2</comment_count>
    <who name="EWS Watchlist">ews-watchlist</who>
    <bug_when>2019-03-07 16:20:51 -0800</bug_when>
    <thetext>Attachment 363951 did not pass style-queue:


ERROR: Source/WTF/wtf/posix/ThreadingPOSIX.cpp:214:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513801</commentid>
    <comment_count>3</comment_count>
      <attachid>363951</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-03-07 16:35:01 -0800</bug_when>
    <thetext>Comment on attachment 363951
patch

LGTM but someone with PlayStation knowledge should also review to confirm if 512K is a reasonable stack size to use.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513839</commentid>
    <comment_count>4</comment_count>
    <who name="Don Olmstead">don.olmstead</who>
    <bug_when>2019-03-07 17:43:05 -0800</bug_when>
    <thetext>(In reply to Mark Lam from comment #3)
&gt; Comment on attachment 363951 [details]
&gt; patch
&gt; 
&gt; LGTM but someone with PlayStation knowledge should also review to confirm if
&gt; 512K is a reasonable stack size to use.

I&apos;m fine with the change. The thing I&apos;m wondering is whether it would be good for WebKit to have a thread&apos;s stack size be more configurable in general during creation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513841</commentid>
    <comment_count>5</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-03-07 17:49:49 -0800</bug_when>
    <thetext>(In reply to Don Olmstead from comment #4)
&gt; (In reply to Mark Lam from comment #3)
&gt; &gt; Comment on attachment 363951 [details]
&gt; &gt; patch
&gt; &gt; 
&gt; &gt; LGTM but someone with PlayStation knowledge should also review to confirm if
&gt; &gt; 512K is a reasonable stack size to use.
&gt; 
&gt; I&apos;m fine with the change. The thing I&apos;m wondering is whether it would be
&gt; good for WebKit to have a thread&apos;s stack size be more configurable in
&gt; general during creation.

See Options::maxPerThreadStackUsage().  For tests, we explicitly set this option to a smaller amount do that tests that overflow the stack can finish faster.

However, this option is at the JSC level, not WTF.  Actual allowed stack capacity is computed as min of Options::maxPerThreadStackUsage() and capacity reported by StackBounds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1513843</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-03-07 17:51:13 -0800</bug_when>
    <thetext>(In reply to Mark Lam from comment #5)
&gt; (In reply to Don Olmstead from comment #4)
&gt; &gt; (In reply to Mark Lam from comment #3)
&gt; &gt; &gt; Comment on attachment 363951 [details]
&gt; &gt; &gt; patch
&gt; &gt; &gt; 
&gt; &gt; &gt; LGTM but someone with PlayStation knowledge should also review to confirm if
&gt; &gt; &gt; 512K is a reasonable stack size to use.
&gt; &gt; 
&gt; &gt; I&apos;m fine with the change. The thing I&apos;m wondering is whether it would be
&gt; &gt; good for WebKit to have a thread&apos;s stack size be more configurable in
&gt; &gt; general during creation.
&gt; 
&gt; See Options::maxPerThreadStackUsage().  For tests, we explicitly set this
&gt; option to a smaller amount do that tests that overflow the stack can finish
&gt; faster.
&gt; 
&gt; However, this option is at the JSC level, not WTF.  Actual allowed stack
&gt; capacity is computed as min of Options::maxPerThreadStackUsage() and
&gt; capacity reported by StackBounds.

Note: it&apos;s done this way because we can&apos;t always control what the OS allocates for stack capacity.  We just make sure that we don&apos;t use more than either limits.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2029837</commentid>
    <comment_count>7</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-04-19 08:39:20 -0700</bug_when>
    <thetext>Current code: https://searchfox.org/wubkat/rev/f8504f25d2ccc6a64957e53ab8c4e42885007fb0/Source/WTF/wtf/posix/ThreadingPOSIX.cpp#314

bool Thread::establishHandle(NewThreadContext* context, std::optional&lt;size_t&gt; stackSize, QOS qos, SchedulingPolicy schedulingPolicy)
{
    pthread_t threadHandle;
    pthread_attr_t attr;
    pthread_attr_init(&amp;attr);
#if HAVE(QOS_CLASSES)
    pthread_attr_set_qos_class_np(&amp;attr, dispatchQOSClass(qos), 0);
#endif
#if HAVE(SCHEDULING_POLICIES)
    pthread_attr_setschedpolicy(&amp;attr, schedPolicy(schedulingPolicy));
#endif
    if (stackSize)
        pthread_attr_setstacksize(&amp;attr, stackSize.value());
    int error = pthread_create(&amp;threadHandle, &amp;attr, wtfThreadEntryPoint, context);
    pthread_attr_destroy(&amp;attr);
    if (error) {
        LOG_ERROR(&quot;Failed to create pthread at entry point %p with context %p&quot;, wtfThreadEntryPoint, context);
        return false;
    }

#if OS(LINUX)
    int policy = schedPolicy(qos, schedulingPolicy);
    if (policy == SCHED_RR)
        RealTimeThreads::singleton().registerThread(*this);
    else {
        struct sched_param param = { };
        error = pthread_setschedparam(threadHandle, policy | SCHED_RESET_ON_FORK, &amp;param);
        if (error)
            LOG_ERROR(&quot;Failed to set sched policy %d for thread %ld: %s&quot;, policy, threadHandle, safeStrerror(error).data());
    }
#else
#if !HAVE(QOS_CLASSES)
    UNUSED_PARAM(qos);
#endif
#if !HAVE(SCHEDULING_POLICIES)
    UNUSED_PARAM(schedulingPolicy);
#endif
#endif

    establishPlatformSpecificHandle(threadHandle);
    return true;
}

___

We don&apos;t seem to have anything specific for &apos;Playstation&apos; platform like this patch was modifying:

#if PLATFORM(PLAYSTATION)

and searching via bug ID - &apos;195439&apos; and didn&apos;t see that this landed.

CCing - Don &amp; Fuji to check, if this is needed or we can close this.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>363951</attachid>
            <date>2019-03-07 16:18:37 -0800</date>
            <delta_ts>2022-02-28 04:07:00 -0800</delta_ts>
            <desc>patch</desc>
            <filename>pthread.diff</filename>
            <type>text/plain</type>
            <size>1540</size>
            <attacher name="Christopher Reid">chris.reid</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XVEYvQ2hhbmdlTG9nIGIvU291cmNlL1dURi9DaGFuZ2VMb2cK
aW5kZXggMWE5YjE5ZDcxMTkuLmU3ZGI1YTExYWI3IDEwMDY0NAotLS0gYS9Tb3VyY2UvV1RGL0No
YW5nZUxvZworKysgYi9Tb3VyY2UvV1RGL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE2IEBACisyMDE5
LTAzLTA3ICBDaHJpc3RvcGhlciBSZWlkICA8Y2hyaXMucmVpZEBzb255LmNvbT4KKworICAgICAg
ICBbUGxheVN0YXRpb25dIEluY3JlYXNlIHRoZSBkZWZhdWx0IHB0aHJlYWQgc3RhY2sgc2l6ZQor
ICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTk1NDM5CisK
KyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgT3VyIHBsYXRm
b3JtIGhhcyBhIHZlcnkgc21hbGwgNjQgS0Igc2Vjb25kYXJ5IHRocmVhZCBzdGFjayBzaXplLgor
ICAgICAgICBUaGlzIHNtYWxsIHN0YWNrIHNpemUgY2F1c2VzIHByb2JsZW1zIHJ1bm5pbmcgbW9z
dCBXZWIgV29ya2VycyB3aXRoIGRlZmF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ZSkgPT0gMCkKKyAgICAgICAgcHRocmVhZF9hdHRyX3NldHN0YWNrc2l6ZSgm
YXR0ciwgc3RkOjptYXgoNTEyICogS0IsIGRlZmF1bHRTdGFja1NpemUpKTsKICNlbmRpZgogICAg
IGludCBlcnJvciA9IHB0aHJlYWRfY3JlYXRlKCZ0aHJlYWRIYW5kbGUsICZhdHRyLCB3dGZUaHJl
YWRFbnRyeVBvaW50LCBjb250ZXh0KTsKICAgICBwdGhyZWFkX2F0dHJfZGVzdHJveSgmYXR0cik7
Cg==
</data>
<flag name="review"
          id="380513"
          type_id="1"
          status="+"
          setter="mark.lam"
    />
          </attachment>
      

    </bug>

</bugzilla>