Uploaded image for project: 'Funtoo Linux'
  1. Funtoo Linux
  2. FL-11330

Python script to identify most appropriate Stage3-uarch for current CPU

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • None
    • run attached script, hopefully it will suggest the best supported uarch

      Having lurked around the bug tracker for a while, I noticed the bug filed by user Kery about their westmere that isn't a westmere, which was subsequently mentioned by drobbins in the February newsletter. Having read an article elsewhere in the past about gcc sometimes doing funny things with -march and -mtune, it occurred to me to try to create a script that compares cpu flags with what gcc expects for each -march value used by funtoo stage3 archives, and recommends the most suitable one.

      This Python (hopefully >=3.7, tested on 3.9) script will read /proc/cpuinfo, and then query gcc several times (once for each value of -march supported by Funtoo, each call should return more or less instantly). It then compares the cpuflags from /proc/cpuinfo with the cflags that gcc wants for each -march. Finally, it will output a ranked list of -march values and suggest the most appropriate one. Ranking is based on the number of matching cpuflags and cflags. A uarch will be disqualified if it wants a cflag that the CPU does not advertise support for. (unless the cflag is ignored in the internal dictionary, or CPU support is implied by a different cpuflag)

      For those particularly concerned about privacy and/or security, this script does not write any files, does not read any user files, does not read any system files other than /proc/cpuinfo, and does not require or make any network connections. It makes repeated calls to a specific gcc command (gcc -march= -Q --help=target). It is entirely possible (though time consuming) to use the internal dictionaries from this script (the first 300 or so lines in a text editor) to manually produce the same results in lieu of running the script.

      I'd appreciate some feedback, particularly from users experienced enough to know whether the output is correct and accurate for their CPU, and especially users owning odd chips like Kery's 'westmere'. I've tried to find a balance beween transparent and concise in the output, to account for smaller or non-scrollable terminals.

      I've tried to comply with PEP8 as far as I think is reasonable, but I need to disclose that although I'm an experienced hobby programmer in several languages, Python is relatively new to me and this is my first major Python project. 

      The long term intent for this is (hopefully) for it to make its way onto the Funtoo live distro image (I still want to say CD) with accompanying instructions in the Handbook suggesting the (new) user runs this script prior to downloading their stage3, in order to help identify which stage3 is most appropriate.

       

      EDIT: script now available at https://code.funtoo.org/bitbucket/users/loonylion/repos/subarchfinder/browse

            Unassigned Unassigned
            loonylion loonylion
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: