Mitochondria are comprised of ~3000 proteins. However, the mitochondrial genome has only 13-14 protein-encoding genes. The remaining 99.6% of mitochondrial proteins are encoded by genes in the nuclear genome. (Wikipedia) Chloroplast genomes are only slightly larger (~100 genes).
Gene regulation and signaling between the nucleus and mitochondria (and between nucleus & chloroplast in plants/algae) occurs in both directions. Anterograde regulation is the signalling from nucleus to mitochondria and was once thought to be the only method of regulating organelle function. We now also know that Retrograde regulation occurs, in which the mitochondria sends signals to the nucleus.
To answer your question directly (but not thoroughly), both the mitochondria and the nucleus are sensing the environment and needs of the cell and signaling to each other to regulate ATP production.
If you want to learn more about retrograde signaling, googling "retrograde regulation" will bring up lots of papers on this topic in different organisms. This paper also has some diagrams of signalling pathways.