1. 1

    Make isn’t great for running commands, because multi-line commands are difficult, and it can’t modify the environment (e.g. change directories or set environment variables)

    So I made .go.sh, which I use heavily. It supports both shell functions and Python functions, and M4 macros. See here for a bunch of examples.

    Make is great for what it’s designed for, though. I (ab)use it plenty; see any of the Makefiles in PoprC.

    1. 3

      See the .ONESHELL phony target. Is this what you want? (i.e multiline and cd)

      1. 1

        That doesn’t work because it creates a new shell, but I want to modify the existing shell.

        1. 1

          I am not sure I understand, are you talking about setting environment variables? This can be done with export in GNU Make.

      2. 2

        Yeah, it’s not the most intuitive tool, of course, and it does have some peculiarities, but I disagree on the point that you can’t modify the environment.

        If you need to cd into a directly, you can write that as part of the recipe. And for environment variables, this is also straightforward.

        mytarget:
          MY_ENV=$(MY_ENV) cd some/directory && ls -ahl
        
      1. 12

        Each clock cycle uses a little bit of power, and if all I’m doing is typing out Latex documents, then I don’t need that many clock cycles. I don’t need one thousand four hundred of them to be precise.

        I recall there being some paper or article that shows doing the work quicker with a higher frequency/power draw then moving into the low frequency is less costly for power savings that doing the work slower at a lower frequency. Basically the CPU would spend more time in sleep states in an ‘on demand’ type governor (run at low freq, but elevate to high freq when utilization is high) vs a governor that always ran at the highest p-state (lowest freq) all the time. I’m having trouble finding the specific paper/article though.. I’ll keep searching.

        1. 15

          Search for “race to idle”

          1. 8
          2. 4

            I remember reading the same thing, but I think it had the added context of being on mobile. Having the CPU awake also meant having other hardware like the radios awake, because it was processing notifications and stuff. In this case, the rest of the hardware is staying awake regardless, so I think it’s really just reducing the number of wasted CPU cycles.

            I’d be interested if you or someone else could find the original source for this again to fact check!

            1. 3

              The counterbalance here is the increasing cost for each 100MHz as frequencies get higher. This is old, but https://images.anandtech.com/doci/9330/a53-power-curve.png shows the measured shape of a real curve. This StackExchange response helps explain why it isn’t flat.

              So factors around race-to-idle include how that power-frequency curve looks, how much stuff you can turn off when idle (often not just the cores; see artemis’s comment) and how CPU-bound you are (2x freq doesn’t guarantee 2x speed because you spend some time waiting on main memory/storage/network).

              Some of that’s workload-dependent, and the frequency governor doesn’t always know the workload when it picks a frequency. Plus you’ve got other goals (like try to be snappy when it affects user-facing latency, but worry less about background work) and other limits (power delivery, thermals, min and max freq the silicon can do). So optimizing battery life ends up really, uh, “fun”!

              (Less related to race-to-idle, but the shape of the power curve also complicates things at the low end; you can’t keep a big chip running at all at 1mW. So modern phones (and a chip Intel is planning) can switch to smaller cores that can draw less power at low load. Also, since they’re tiny you can spam the chip with more of them, so e.g. Intel’s planning one large core and four small. Fun times.)

              1. 1

                Ooh, today somebody happened to post a couple pretty charts of recent high-end Intel desktop chips’ power/frequency curves, and charted speed per watt as a bonus. They also fit a logarithmic curve to it, modeling power needs as growing exponentially to hit a given level of perf, and it looks like it worked reasonably well.

              2. 1

                Yes, I remember reading the same thing. But, maybe on a CPU this old it isn’t as efficient as transitioning in and out of low power states? Just a guess, assuming his claim of +1 hour is true.

                1. 1

                  Maybe it’s not linear. The comparison between ‘low freq’ and ‘high freq’ for that study could be comparing something like 40% (of the available clock range) vs 90%? And maybe at 1% the CPU power draw is so much lower that it’s even better than race-to-idle (but perhaps considered to be an unlikely/uncommon configuration).

                  1. 1

                    The power consumption of a CMOS circuit scales with the square of the operating voltage, though, so intuitively I would expect that 100 ms at 0.5V to be more energy-efficient then 50ms at 1.0V. Chips are extremely complex devices, though, and I’m probably ignorant about a power-saving strategy or physical effect that side-steps this. Please let me know when you find that article - I’m curious to see which of my assumptions have been violated.

                    1. 1

                      I found it and put the link in another comment

                    2. 1

                      This makes a lot of sense and mirrors my experience with an X220 on OpenBSD. I got about one more hour of battery life (about 5 hours -> 6 hours ish) just by allowing it to run at a higher frequency but still spend 95% of its time at a lower one.

                      Also, while the tools built into OpenBSD do a good job of controlling power usage, I found I was getting even better battery life in a standard Arch Linux instal with no configuration of powertop or anything else.

                    1. 1

                      I tried this, but I’d like something where I can use cd or source.

                      So I made this: https://gist.github.com/HackerFoo/19f3666e7feb93df2e5b4d2c22991029

                      The commands are just what I’m working on right now; it’s easy to modify, and sources itself each time the go function is called.

                      1. 1

                        Implicitly sourcing a bash script that happens to be in the same directory seems really insecure.

                        1. 1

                          It expands to an absolute path: source ~/.go.bash

                          1. 1

                            Also, isn’t make or just almost as insecure?

                            1. 1

                              Oh, you’re right. I misread it. I thought it was project-specific, but it’s actually system-wide. My mistake. Carry on.

                        1. 1

                          Note that Linus’s comment was about code where the VLA would always be the same length for a given architecture, so a fixed size should have been computed at compile time.

                          1. 2

                            I’m totally going to read this carefully when I get some time. But meanwhile, just at a glance, the responsive layout with the columns is amazing! Readable and no space wasted! Why don’t all websites do this?

                            1. 1

                              Thanks! I spent a lot of time on the design.

                              Some people don’t like scrolling up and down, but I can’t stand the ridiculously large margins on a wide screen monitor, and I like the look of an academic paper mixed with some hand-drawn elements.

                            1. 1

                              Your slideshow presentation was really interesting given it mixes concatenative and functional. I suggest submitting it next.

                              1. 2

                                Thanks. I guess I should update the presentation, since it was a year and a half ago, and then fill it in to make a full article.

                                1. 1

                                  That sounds even better!

                              1. 2

                                I took a short break from PoprC to polish up a C library I’ve derived from that project that I call Startle.

                                It has a lot of nice features that make it much easier to start a new C project, while staying lightweight and not requiring any heap allocation.

                                I have also made an example project to which I’ve been adding bits of code to demonstrate usage of the library.

                                I hope to get some time to fix some more test cases with PoprC so I can get closer to getting the library working again.