P0171 is System Too Lean (Bank 1) this could be the MAF or PCV..or a vacuum leak.
it DEFINITELY sounds like you are doing this car no favors by driving it...that knock could be a bad sign.
I don't understand why everyone keeps saying PCV on a 3.9. The 3.9 doesn't use a PCV like the 3.0, it's basically a tube that runs from the drivers side valve cover to the intake tube. The misguidance people are receiving about PCV valves on the v8 is frustrating.
To the OP. I went back and forth with Joegr on this, I have the same code p0171 or whatever bank 1 lean is. There are a few posibilities to this:
1. Vacuum leak in intake - use starter fluid, propane, whatever you want, and start inspecting around passenger side intake manifold and intake. See if the rpm's change when spraying - if it does, you have a air leak.
2. Misfire in pass side coil.
3. Fuel pump isn't putting out enough. Simple test to do with fuel pressure gauge, 30-55psi is normal range. Not likely scenerio, but possible.
4. Clogged fuel injector. Harder to test. This would be a dealership or decent shop that can test them.
5. Possible a really bad timing issue, especially with the knocking sound. Like the last few members mentioned, take off the valve cover and check to see if the cam flats line up.
Along with the fuel pump and injector issues, you can have a clogged fuel filter. When was the last time that was changed out? Not sure if it would cause your "knocking sound" but anything can happen when fuel/air mixtures are out of wack and detonation is off