Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8147910

Cache initial active_processor_count

    Details

    • Subcomponent:
    • Resolved In Build:
      b131

      Backports

        Description

        The active_processor_count is the number of CPUs available to the JVM process and as such can change dynamically. For some uses it may be beneficial to cache the initial active processor count and use that value for decision making - eg for GC ergonomics.

        The cached value could also be use by the os::print_cpu_info, and other routines, that want to report cpu information but may be called in a crash context and so are limited in what they attempt to do. In particular they report the number of configured processors (processor_count()) not the number of available processors (active_processor_count()), because the former is an unchanging value cached at system initialization, while the latter requires system calls that make not be possible in a crash context.

          Issue Links

            Activity

            Hide
            dholmes David Holmes added a comment -
            I think this simple enhancement should be considered for JDK 9.
            Show
            dholmes David Holmes added a comment - I think this simple enhancement should be considered for JDK 9.
            Hide
            tschatzl Thomas Schatzl added a comment - - edited
            Prototype for this introducing an initial_active_processor_count() variable to fix crashes for changing os::processor_count() return values for G1.

            This has been made to kind of solve the in JDK-8149331 mentioned backed-out change.

            Not sure how this real issue ties into this. Additionally, this CR suggests further improvements. I could spend some little more work on this, but I do not exactly know where else you want this value to be used.

            Otherwise I suggest separating this issue and fixing the crashes.
            Show
            tschatzl Thomas Schatzl added a comment - - edited Prototype for this introducing an initial_active_processor_count() variable to fix crashes for changing os::processor_count() return values for G1. This has been made to kind of solve the in JDK-8149331 mentioned backed-out change. Not sure how this real issue ties into this. Additionally, this CR suggests further improvements. I could spend some little more work on this, but I do not exactly know where else you want this value to be used. Otherwise I suggest separating this issue and fixing the crashes.
            Hide
            dholmes David Holmes added a comment -
            I would argue that adding this API should be considered a bug-fix now not an enhancement. When I filed this it seemed something potentially useful - a record of the initial number of available processors. But such an API is now required by the GC to fix JDK-8161993 - we need to size the GC based on the actual available number of processors (active_processor_count) but that value must then remain constant for use in other parts of the GC. While the GC could keep an internal cached value for its own use it makes more sense to use this proposed API.
            Show
            dholmes David Holmes added a comment - I would argue that adding this API should be considered a bug-fix now not an enhancement. When I filed this it seemed something potentially useful - a record of the initial number of available processors. But such an API is now required by the GC to fix JDK-8161993 - we need to size the GC based on the actual available number of processors (active_processor_count) but that value must then remain constant for use in other parts of the GC. While the GC could keep an internal cached value for its own use it makes more sense to use this proposed API.
            Hide
            dholmes David Holmes added a comment -
            In os.cpp I would modify os::print_cpu_info as follows:

            void os::print_cpu_info(outputStream* st, char* buf, size_t buflen) {
              // cpu
              st->print("CPU:");
              st->print("total %d", os::processor_count());
              // It's not safe to query number of active processors after crash
              // st->print("(active %d)", os::active_processor_count());
            + // but we can report the initial number of active processors
            + st->print(" (initial available %d)", os::initial_active_processor_count());
              st->print(" %s", VM_Version::features_string());
              st->cr();
              pd_print_cpu_info(st, buf, buflen);
            }

            and I agree that I think it is safe to initialize initial_active_processor_count in os::init_before_ergo() - which is shared code.
            Show
            dholmes David Holmes added a comment - In os.cpp I would modify os::print_cpu_info as follows: void os::print_cpu_info(outputStream* st, char* buf, size_t buflen) {   // cpu   st->print("CPU:");   st->print("total %d", os::processor_count());   // It's not safe to query number of active processors after crash   // st->print("(active %d)", os::active_processor_count()); + // but we can report the initial number of active processors + st->print(" (initial available %d)", os::initial_active_processor_count());   st->print(" %s", VM_Version::features_string());   st->cr();   pd_print_cpu_info(st, buf, buflen); } and I agree that I think it is safe to initialize initial_active_processor_count in os::init_before_ergo() - which is shared code.
            Hide
            tschatzl Thomas Schatzl added a comment -
            Changed to bug as per David's suggestion. This is missing functionality.
            Show
            tschatzl Thomas Schatzl added a comment - Changed to bug as per David's suggestion. This is missing functionality.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/hs/hotspot/rev/42bdfbb535a2
            User: tschatzl
            Date: 2016-07-26 10:17:13 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/hs/hotspot/rev/42bdfbb535a2 User: tschatzl Date: 2016-07-26 10:17:13 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/42bdfbb535a2
            User: lana
            Date: 2016-08-10 20:19:27 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/42bdfbb535a2 User: lana Date: 2016-08-10 20:19:27 +0000

              People

              • Assignee:
                tschatzl Thomas Schatzl
                Reporter:
                dholmes David Holmes
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: